diograph 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/diograph.rb +127 -122
- data/lib/diograph/connection.rb +24 -0
- data/lib/diograph/diory.rb +41 -0
- data/lib/diograph/room.rb +21 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ea38f845d2143ac9939193e7cb846e3e44705e9
|
4
|
+
data.tar.gz: 86ff681d76badebdc3c947a94db6563fb5aab293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 880af575ad718dfadfc8c9a74343629665d581eadb7a632eba0c8e968e1d23fab1a2dc98fe648306099101c4649040bb567015409c9cb45e09f3f1d2d3b3b619
|
7
|
+
data.tar.gz: 3cce514d4db4266ba10cda2bb16408332678faeafd5790ef29c8ccc7cb332ec25b25e486cffc64fb3e5d0ca6ea767f0aead61ff44d308905e17246eb94cd2010
|
data/lib/diograph.rb
CHANGED
@@ -1,144 +1,149 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
diograph
|
13
|
-
|
1
|
+
require 'diograph/room'
|
2
|
+
require 'diograph/diory'
|
3
|
+
require 'diograph/connection'
|
4
|
+
require 'diograph/diograph'
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
module Diograph
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def create_room_from_diograph(diograph)
|
13
|
+
# Parse diograph to hash
|
14
|
+
diograph = JSON.parse(diograph) if diograph.class == String
|
15
|
+
# Create room
|
16
|
+
room = create_room_from_attributes(diograph)
|
17
|
+
diograph["diories"].map do |diory_hash|
|
18
|
+
create_diory_and_connections_from_diograph(room, diory_hash)
|
19
|
+
end
|
20
|
+
room
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_connections_and_related_diories(diory, diory_hash)
|
24
|
+
diory_hash["connections"].keys.each do |key|
|
25
|
+
to_diory = find_or_create_diory_from_attributes(diory.room, diory_hash["connections"][key]["diory"])
|
26
|
+
diory.connect_to(to_diory)
|
27
|
+
end
|
14
28
|
end
|
15
|
-
room
|
16
|
-
end
|
17
29
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
diory_hash = JSON.parse(diory_hash) if diory_hash.class == String
|
27
|
-
diory = find_or_create_diory_from_attributes(room, diory_hash)
|
28
|
-
diory_hash["connections"].keys.each do |key|
|
29
|
-
connection = create_connection_from_hash(diory, diory_hash["connections"][key])
|
30
|
-
diory.connections << connection
|
30
|
+
def create_diory_and_connections_from_diograph(room, diory_hash)
|
31
|
+
diory_hash = JSON.parse(diory_hash) if diory_hash.class == String
|
32
|
+
diory = find_or_create_diory_from_attributes(room, diory_hash)
|
33
|
+
diory_hash["connections"].keys.each do |key|
|
34
|
+
connection = create_connection_from_hash(diory, diory_hash["connections"][key])
|
35
|
+
diory.connections << connection
|
36
|
+
end
|
37
|
+
diory
|
31
38
|
end
|
32
|
-
diory
|
33
|
-
end
|
34
39
|
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def self.create_room_from_attributes(args={}, user=nil)
|
41
|
-
room = Room.new(
|
42
|
-
name: args["name"],
|
43
|
-
room_id: args["roomID"],
|
44
|
-
created: args["created"],
|
45
|
-
modified: args["modified"]
|
46
|
-
)
|
47
|
-
room.user = user unless user.nil?
|
48
|
-
room.save if room.respond_to?(:save)
|
49
|
-
room
|
50
|
-
end
|
41
|
+
################################
|
42
|
+
### FROM diograph TO diories ###
|
43
|
+
################################
|
51
44
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
45
|
+
def create_room_from_attributes(args={})
|
46
|
+
room = Room.new(
|
47
|
+
name: args["name"],
|
48
|
+
room_id: args["roomID"],
|
49
|
+
created: args["created"],
|
50
|
+
modified: args["modified"]
|
51
|
+
)
|
52
|
+
room.save if room.respond_to?(:save)
|
53
|
+
room
|
58
54
|
end
|
59
|
-
end
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
modified: args["modified"] || DateTime.now,
|
70
|
-
created: args["created"] || DateTime.now,
|
71
|
-
room: room
|
72
|
-
)
|
73
|
-
room.diories << diory if diory.respond_to?(:save)
|
74
|
-
diory.save if diory.respond_to?(:save)
|
75
|
-
diory
|
76
|
-
end
|
56
|
+
def find_or_create_diory_from_attributes(room, args={})
|
57
|
+
existing_diory = room.diories.find{|d| d.diory_id == args["ID"]}
|
58
|
+
if existing_diory.nil?
|
59
|
+
create_diory_from_attributes(room, args)
|
60
|
+
else
|
61
|
+
existing_diory
|
62
|
+
end
|
63
|
+
end
|
77
64
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
65
|
+
def create_diory_from_attributes(room, args={})
|
66
|
+
diory = Diory.new(
|
67
|
+
diory_id: args["diory_id"] || args["ID"],
|
68
|
+
name: args["name"],
|
69
|
+
diory_type: args["type"],
|
70
|
+
date: args["date"],
|
71
|
+
address: args["address"],
|
72
|
+
background: args["background"],
|
73
|
+
modified: args["modified"] || DateTime.now,
|
74
|
+
created: args["created"] || DateTime.now,
|
75
|
+
room: room
|
76
|
+
)
|
77
|
+
room.diories << diory if diory.respond_to?(:save)
|
78
|
+
diory.save if diory.respond_to?(:save)
|
79
|
+
diory
|
80
|
+
end
|
89
81
|
|
82
|
+
def create_connection_from_hash(diory, connection_hash)
|
83
|
+
connected_diory_hash = connection_hash["diory"]
|
84
|
+
to_diory = find_or_create_diory_from_attributes(diory.room, connected_diory_hash)
|
85
|
+
connection = Connection.new(
|
86
|
+
from_diory: diory,
|
87
|
+
to_diory: to_diory,
|
88
|
+
room_id: diory.room.room_id
|
89
|
+
)
|
90
|
+
connection.save if connection.respond_to?(:save)
|
91
|
+
connection
|
92
|
+
end
|
90
93
|
|
91
|
-
################################
|
92
|
-
### FROM diories TO diograph ###
|
93
|
-
################################
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
roomID: room.room_id,
|
99
|
-
created: room.created,
|
100
|
-
modified: room.modified,
|
101
|
-
diories: room.diories.map{|d| create_from_diory(d)}
|
102
|
-
}
|
103
|
-
return JSON.parse dg.to_json # stringify keys
|
104
|
-
end
|
95
|
+
################################
|
96
|
+
### FROM diories TO diograph ###
|
97
|
+
################################
|
105
98
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
dg
|
119
|
-
|
120
|
-
|
99
|
+
def create_from_room(room)
|
100
|
+
dg = {
|
101
|
+
name: room.name,
|
102
|
+
roomID: room.room_id,
|
103
|
+
created: room.created,
|
104
|
+
modified: room.modified,
|
105
|
+
diories: room.diories.map{|d| create_from_diory(d)}
|
106
|
+
}
|
107
|
+
return JSON.parse dg.to_json # stringify keys
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_from_diory(diory, include_connections=true)
|
111
|
+
dg = {
|
112
|
+
diory_id: diory.diory_id,
|
113
|
+
type: diory.diory_type,
|
114
|
+
text: diory.name,
|
115
|
+
image: diory.background,
|
116
|
+
style: { text: { color: "white"} },
|
117
|
+
data: { geo: { latitude: diory.latitude, longitude: diory.longitude, zoom: 10 } },
|
118
|
+
address: diory.address,
|
119
|
+
date: diory.date,
|
120
|
+
created: diory.created,
|
121
|
+
modified: diory.modified,
|
122
|
+
}
|
123
|
+
if include_connections
|
124
|
+
dg[:diorys] = {}
|
125
|
+
diory.connections.each_with_index do |c, i|
|
126
|
+
dg[:diorys][i] = create_from_connection(c)
|
127
|
+
end
|
121
128
|
end
|
129
|
+
return JSON.parse dg.to_json # stringify keys
|
122
130
|
end
|
123
|
-
return JSON.parse dg.to_json # stringify keys
|
124
|
-
end
|
125
131
|
|
126
132
|
|
127
|
-
|
133
|
+
### 0.1.0 stuff ###
|
128
134
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
def create_from_connection(connection)
|
136
|
+
d = connection.to_diory
|
137
|
+
connection_dg = create_from_diory(d, false)
|
138
|
+
connection_dg
|
139
|
+
end
|
140
|
+
|
141
|
+
def is_equal(diograph1, diograph2)
|
142
|
+
one = diograph1["diories"].sort_by{|d| d["ID"]} unless diograph1.nil?
|
143
|
+
two = diograph2["diories"].sort_by{|d| d["ID"]} unless diograph2.nil?
|
144
|
+
one == two
|
145
|
+
end
|
137
146
|
|
138
|
-
def self.is_equal(diograph1, diograph2)
|
139
|
-
one = diograph1["diories"].sort_by{|d| d["ID"]} unless diograph1.nil?
|
140
|
-
two = diograph2["diories"].sort_by{|d| d["ID"]} unless diograph2.nil?
|
141
|
-
one == two
|
142
147
|
end
|
143
148
|
|
144
149
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Diograph
|
2
|
+
|
3
|
+
class Connection
|
4
|
+
|
5
|
+
attr_reader :from_diory, :to_diory
|
6
|
+
|
7
|
+
def initialize(args={})
|
8
|
+
@from_diory = args[:from_diory]
|
9
|
+
@to_diory = args[:to_diory]
|
10
|
+
end
|
11
|
+
|
12
|
+
def from_diory_id
|
13
|
+
nil if @from_diory.nil?
|
14
|
+
@from_diory.diory_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_diory_id
|
18
|
+
nil if @to_diory.nil?
|
19
|
+
@to_diory.diory_id
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Diograph
|
2
|
+
|
3
|
+
class Diory
|
4
|
+
|
5
|
+
attr_reader :diory_id, :name, :diory_type, :date, :address, :background, :latitude, :longitude, :created, :modified
|
6
|
+
attr_reader :room, :connections, :connected_diories
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
@diory_id = args[:diory_id] || args[:ID]
|
10
|
+
@name = args[:name]
|
11
|
+
@diory_type = args[:diory_type]
|
12
|
+
@date = args[:date]
|
13
|
+
@address = args[:address]
|
14
|
+
@background = args[:background]
|
15
|
+
@latitude = args[:latitude]
|
16
|
+
@longitude = args[:longitude]
|
17
|
+
@created = args[:created]
|
18
|
+
@modified = args[:modified]
|
19
|
+
|
20
|
+
@room = args[:room]
|
21
|
+
@room.diories << self if @room
|
22
|
+
|
23
|
+
@connections = args[:connections] || []
|
24
|
+
@connected_diories = args[:connected_diories] || []
|
25
|
+
end
|
26
|
+
|
27
|
+
def connect_to(to_diory)
|
28
|
+
connection = Connection.new(from_diory: self, to_diory: to_diory)
|
29
|
+
@connections << connection
|
30
|
+
@connected_diories << to_diory
|
31
|
+
to_diory.connections << connection
|
32
|
+
to_diory.connected_diories << self
|
33
|
+
end
|
34
|
+
|
35
|
+
def connected_diories=(connected_diories)
|
36
|
+
@connected_diories = connected_diories
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Diograph
|
2
|
+
|
3
|
+
class Room
|
4
|
+
|
5
|
+
attr_reader :room_id, :name, :modified, :created, :diories
|
6
|
+
|
7
|
+
def initialize(args={})
|
8
|
+
|
9
|
+
# Attributes
|
10
|
+
@room_id = args[:room_id]
|
11
|
+
@name = args[:name]
|
12
|
+
@modified = args[:modified]
|
13
|
+
@created = args[:created]
|
14
|
+
|
15
|
+
# Relations
|
16
|
+
@diories = args[:diories] || []
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diograph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jvalanen
|
@@ -14,14 +14,14 @@ dependencies:
|
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: Library to deal with diographs in Personal Web applications
|
@@ -31,6 +31,9 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/diograph.rb
|
34
|
+
- lib/diograph/connection.rb
|
35
|
+
- lib/diograph/diory.rb
|
36
|
+
- lib/diograph/room.rb
|
34
37
|
homepage: http://rubygems.org/gems/diograph
|
35
38
|
licenses: []
|
36
39
|
metadata: {}
|
@@ -40,17 +43,17 @@ require_paths:
|
|
40
43
|
- lib
|
41
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
45
|
requirements:
|
43
|
-
- -
|
46
|
+
- - ">="
|
44
47
|
- !ruby/object:Gem::Version
|
45
48
|
version: '0'
|
46
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
50
|
requirements:
|
48
|
-
- -
|
51
|
+
- - ">="
|
49
52
|
- !ruby/object:Gem::Version
|
50
53
|
version: '0'
|
51
54
|
requirements: []
|
52
55
|
rubyforge_project:
|
53
|
-
rubygems_version: 2.
|
56
|
+
rubygems_version: 2.6.13
|
54
57
|
signing_key:
|
55
58
|
specification_version: 4
|
56
59
|
summary: Library to deal with diographs in Personal Web applications
|