diograph 0.1.0 → 0.3.1
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 +105 -5
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9330e603168cb057aa2a524890765f8bc9f9075
|
4
|
+
data.tar.gz: 54cb41f4b889d8bb84bc0f6b7cec1c3aaf2dcc2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a367a80542e8ba94031627271c0af8b7686228381e55578b13b494982a71aaaa9914e0396461e40b2a716a9c0aa1613fc95d7ab7abcb6fda1766af44bb6aa489
|
7
|
+
data.tar.gz: d7499cff811b7614d5555feafefabbd1522e06ac96b7ecb8a09ec356ec2f5d84edc38624088aa187060b781983cf4079a22f6aad7b407f1a0f82cc51e6ac2520
|
data/lib/diograph.rb
CHANGED
@@ -1,7 +1,97 @@
|
|
1
|
-
require '
|
1
|
+
# require 'room'
|
2
|
+
# require 'diory'
|
3
|
+
# require 'connection'
|
2
4
|
|
3
5
|
class Diograph
|
4
6
|
|
7
|
+
def self.create_room_from_diograph(diograph, user=nil)
|
8
|
+
# Parse diograph to hash
|
9
|
+
diograph = JSON.parse(diograph) if diograph.class == String
|
10
|
+
# Create room
|
11
|
+
room = user.nil? ? create_room_from_attributes(diograph) : create_room_from_attributes(diograph, user)
|
12
|
+
diograph["diories"].map do |diory_hash|
|
13
|
+
create_diory_and_connections_from_diograph(room, diory_hash)
|
14
|
+
end
|
15
|
+
room
|
16
|
+
end
|
17
|
+
|
18
|
+
# def self.create_connections_and_related_diories(diory, diory_hash)
|
19
|
+
# diory_hash["connections"].keys.each do |key|
|
20
|
+
# to_diory = find_or_create_diory_from_attributes(diory.room, diory_hash["connections"][key]["diory"])
|
21
|
+
# diory.connect_to(to_diory)
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
|
25
|
+
def self.create_diory_and_connections_from_diograph(room, diory_hash)
|
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
|
31
|
+
end
|
32
|
+
diory
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
################################
|
37
|
+
### FROM diograph TO diories ###
|
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
|
51
|
+
|
52
|
+
def self.find_or_create_diory_from_attributes(room, args={})
|
53
|
+
existing_diory = room.diories.find{|d| d.diory_id == args["ID"]}
|
54
|
+
if existing_diory.nil?
|
55
|
+
create_diory_from_attributes(room, args)
|
56
|
+
else
|
57
|
+
existing_diory
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.create_diory_from_attributes(room, args={})
|
62
|
+
diory = Diory.new(
|
63
|
+
diory_id: args["ID"],
|
64
|
+
name: args["name"],
|
65
|
+
diory_type: args["type"],
|
66
|
+
date: args["date"],
|
67
|
+
address: args["address"],
|
68
|
+
background: args["background"],
|
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
|
77
|
+
|
78
|
+
def self.create_connection_from_hash(diory, connection_hash)
|
79
|
+
connected_diory_hash = connection_hash["diory"]
|
80
|
+
to_diory = find_or_create_diory_from_attributes(diory.room, connected_diory_hash)
|
81
|
+
connection = Connection.new(
|
82
|
+
from_diory: diory,
|
83
|
+
to_diory: to_diory,
|
84
|
+
room_id: diory.room.room_id
|
85
|
+
)
|
86
|
+
connection.save if connection.respond_to?(:save)
|
87
|
+
connection
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
################################
|
92
|
+
### FROM diories TO diograph ###
|
93
|
+
################################
|
94
|
+
|
5
95
|
def self.create_from_room(room)
|
6
96
|
dg = {
|
7
97
|
name: room.name,
|
@@ -26,15 +116,25 @@ class Diograph
|
|
26
116
|
}
|
27
117
|
if include_connections
|
28
118
|
dg[:connections] = {}
|
29
|
-
diory.
|
30
|
-
dg[:connections][
|
31
|
-
dg[:connections][d.diory_id]["roomID"] = d.room.room_id
|
32
|
-
dg[:connections][d.diory_id]["diory"] = create_from_diory(d, false)
|
119
|
+
diory.connections.each do |c|
|
120
|
+
dg[:connections][c.to_diory.diory_id] = self.create_from_connection(c)
|
33
121
|
end
|
34
122
|
end
|
35
123
|
return JSON.parse dg.to_json # stringify keys
|
36
124
|
end
|
37
125
|
|
126
|
+
|
127
|
+
### 0.1.0 stuff ###
|
128
|
+
|
129
|
+
def self.create_from_connection(connection)
|
130
|
+
d = connection.to_diory
|
131
|
+
connection_dg = {}
|
132
|
+
# connection_dg["ID"] = connection.connection_id
|
133
|
+
connection_dg["roomID"] = d.room.room_id
|
134
|
+
connection_dg["diory"] = create_from_diory(d, false)
|
135
|
+
connection_dg
|
136
|
+
end
|
137
|
+
|
38
138
|
def self.is_equal(diograph1, diograph2)
|
39
139
|
one = diograph1["diories"].sort_by{|d| d["ID"]} unless diograph1.nil?
|
40
140
|
two = diograph2["diories"].sort_by{|d| d["ID"]} unless diograph2.nil?
|
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diograph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jvalanen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
12
|
-
dependencies:
|
11
|
+
date: 2016-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: Library to deal with diographs in Personal Web applications
|
14
|
-
email: jouni
|
28
|
+
email: jouni@diory.me
|
15
29
|
executables: []
|
16
30
|
extensions: []
|
17
31
|
extra_rdoc_files: []
|
@@ -26,17 +40,17 @@ require_paths:
|
|
26
40
|
- lib
|
27
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
28
42
|
requirements:
|
29
|
-
- -
|
43
|
+
- - '>='
|
30
44
|
- !ruby/object:Gem::Version
|
31
45
|
version: '0'
|
32
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
47
|
requirements:
|
34
|
-
- -
|
48
|
+
- - '>='
|
35
49
|
- !ruby/object:Gem::Version
|
36
50
|
version: '0'
|
37
51
|
requirements: []
|
38
52
|
rubyforge_project:
|
39
|
-
rubygems_version: 2.
|
53
|
+
rubygems_version: 2.0.14.1
|
40
54
|
signing_key:
|
41
55
|
specification_version: 4
|
42
56
|
summary: Library to deal with diographs in Personal Web applications
|