diograph 0.0.1.1 → 0.1.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 +42 -349
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6504cdb7428d41f73daf4fb2ecd0f4315fc5e33d
|
4
|
+
data.tar.gz: 48153fae1c00bc1a174a125bba475a9d150a73dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be53af76ed24f3a058a7668a5775107bef8245b9f52beac74afa4d1581acb3ae8dc41ef1b7406608b52a9ae4a0008f0667b8c01705e6e3c66c2bc187041beb23
|
7
|
+
data.tar.gz: 70aa91b39c55c8914d662f18b8a6e481be21125fa88639c93fccdb29635036f077a24da5c043e35bce6326c5dbbb81c0aed50c1649f388dfd13d9f2cbd61668f
|
data/lib/diograph.rb
CHANGED
@@ -1,351 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
diograph_obj.diories << diory
|
44
|
-
end
|
45
|
-
diograph_obj
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
def self.create_from_database
|
50
|
-
|
51
|
-
diograph = Diograph.new
|
52
|
-
diograph.diories = Diory.all
|
53
|
-
diograph
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.new_hash_from_diograph(diograph)
|
58
|
-
JSON.parse(diograph)
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.new_hash
|
62
|
-
self.empty_static_hash_template # at the bottom of this class
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
def to_diograph
|
67
|
-
diograph_hash = self.to_diograph_hash
|
68
|
-
JSON.pretty_generate(diograph_hash)
|
69
|
-
end
|
70
|
-
|
71
|
-
def to_diograph_hash
|
72
|
-
diograph_hash = Diograph.new_hash
|
73
|
-
@diories.each do |diory|
|
74
|
-
diograph_hash[Diograph::ATTRIBUTES['diories']] << diory.to_diograph_hash
|
75
|
-
end
|
76
|
-
diograph_hash
|
77
|
-
end
|
78
|
-
|
79
|
-
def to_s
|
80
|
-
self.to_diograph
|
81
|
-
# puts JSON.pretty_generate(self.to_diograph)
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def self.empty_static_hash_template
|
89
|
-
|
90
|
-
diograph = {
|
91
|
-
"@context" => {
|
92
|
-
|
93
|
-
"xsd"=>"http://www.w3.org/2001/XMLSchema#",
|
94
|
-
"prov"=>"http://www.w3.org/ns/prov#",
|
95
|
-
"dct"=>"http://purl.org/dc/terms/",
|
96
|
-
"css"=>"http://www.w3.org/wiki/CSS/Properties/",
|
97
|
-
"diograph"=>"http://diograph.org/",
|
98
|
-
"diory"=>"http://diograph.org/diory/",
|
99
|
-
|
100
|
-
"id"=>"@id",
|
101
|
-
"type"=>"@type",
|
102
|
-
"name"=>"dct:title",
|
103
|
-
|
104
|
-
"style" => "diory:style",
|
105
|
-
"background-color" => "css:background-color",
|
106
|
-
"background-image" => "css:background-image",
|
107
|
-
|
108
|
-
"modified" => {
|
109
|
-
"@id" => "dct:modified",
|
110
|
-
"@type" => "xsd:dateTime"
|
111
|
-
},
|
112
|
-
"created" => {
|
113
|
-
"@id" => "dct:created",
|
114
|
-
"@type" => "xsd:dateTime"
|
115
|
-
},
|
116
|
-
"data" => "diory:data",
|
117
|
-
|
118
|
-
"IRI" => {
|
119
|
-
"@id" => "dct:abstract",
|
120
|
-
"@type" => "@id"
|
121
|
-
},
|
122
|
-
"www" => {
|
123
|
-
"@id" => "dct:source",
|
124
|
-
"@type" => "xsd:anyURI"
|
125
|
-
},
|
126
|
-
"view" => {
|
127
|
-
"@id" => "diory:view",
|
128
|
-
"@container" => "@list"
|
129
|
-
},
|
130
|
-
"connected" => {
|
131
|
-
"@id" => "diory:connected",
|
132
|
-
"@container" => "@list"
|
133
|
-
},
|
134
|
-
|
135
|
-
"ratio" => "diory:ratio",
|
136
|
-
"position" => "diory:position",
|
137
|
-
"top" => "css:top",
|
138
|
-
"left" => "css:left",
|
139
|
-
"height" => "css:height",
|
140
|
-
"padding-bottom" => "css:padding-bottom",
|
141
|
-
"width" => "css:width",
|
142
|
-
|
143
|
-
"app" => "dct:agent",
|
144
|
-
"icon" => "http://purl.org/dc/dcmitype/Image",
|
145
|
-
|
146
|
-
"owl-time" => "http://www.w3.org/2006/time#",
|
147
|
-
"datetime" => "owl-time:inXSDDateTime",
|
148
|
-
"dateStart" => {
|
149
|
-
"@id" => "owl-time:hasBeginning",
|
150
|
-
"@type" => "datetime"
|
151
|
-
},
|
152
|
-
"dateStop" => {
|
153
|
-
"@id" => "owl-time:hasEnding",
|
154
|
-
"@type" => "datetime"
|
155
|
-
},
|
156
|
-
"duration" => "owl-time:duration",
|
157
|
-
|
158
|
-
"geo" => "http://ld.geojson.org/vocab#",
|
159
|
-
"geometry" => "geo:geometry",
|
160
|
-
"coordinates" => {
|
161
|
-
"@id" => "geo:coordinates",
|
162
|
-
"@container" => "@list"
|
163
|
-
},
|
164
|
-
"Polygon" => "geo:Polygon",
|
165
|
-
"Point" => "geo:Point",
|
166
|
-
|
167
|
-
"dct" => "http://purl.org/dc/terms/",
|
168
|
-
"distance" => "dct:SizeOrDuration",
|
169
|
-
|
170
|
-
"note" => "http://purl.org/dc/dcmitype/Text",
|
171
|
-
"photo" => "http://purl.org/dc/dcmitype/image"
|
172
|
-
|
173
|
-
},
|
174
|
-
|
175
|
-
"@graph" => []
|
176
|
-
}
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
|
181
|
-
end
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
class Diory
|
186
|
-
|
187
|
-
attr_accessor :app_id, :app_related_type, :app_name, :name, :url, :diory_id, :date, :geo, :data, :type, :thumbnail, :created_at, :updated_at, :strong_relations, :weak_relations
|
188
|
-
|
189
|
-
|
190
|
-
def initialize
|
191
|
-
|
192
|
-
@app_id = nil
|
193
|
-
@app_related_type = nil
|
194
|
-
@app_name = nil
|
195
|
-
|
196
|
-
@name = nil
|
197
|
-
@url = nil
|
198
|
-
@diory_id = nil
|
199
|
-
@date = nil
|
200
|
-
@geo = nil
|
201
|
-
@data = {}
|
202
|
-
@type = "diory"
|
203
|
-
@thumbnail = nil
|
204
|
-
|
205
|
-
@created_at = nil
|
206
|
-
@updated_at = nil
|
207
|
-
|
208
|
-
@strong_relations = []
|
209
|
-
@weak_relations = []
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
|
214
|
-
def self.generate_id(app_id, app_related_type, name)
|
215
|
-
# Cut down too long names
|
216
|
-
if name.size > 25
|
217
|
-
name = name[0..24]
|
218
|
-
end
|
219
|
-
# Encode name suitable for an URL
|
220
|
-
name = URI.escape(name, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
221
|
-
# Compose the id
|
222
|
-
return app_id + app_related_type + '/' + name
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
def relate(diory)
|
227
|
-
self.strong_relations.push(diory)
|
228
|
-
diory.weak_relations.push(self)
|
229
|
-
end
|
230
|
-
|
231
|
-
|
232
|
-
# Create Diory itself
|
233
|
-
def self.create_from_hash(diory_hash)
|
234
|
-
|
235
|
-
# Create new or load existing diory
|
236
|
-
diory = Diory.new
|
237
|
-
diory.load_attributes_from_hash(diory_hash)
|
238
|
-
|
239
|
-
# Relations or no relations?
|
240
|
-
relations = diory_hash["#{Diograph::ATTRIBUTES['strong_relations']}"].blank? ? false : true
|
241
|
-
|
242
|
-
# Save and update relations
|
243
|
-
if relations
|
244
|
-
# Go through relations in JSON-LD
|
245
|
-
diory_hash["#{Diograph::ATTRIBUTES['strong_relations']}"].each do |related_hash|
|
246
|
-
# Create diory from JSON-LD
|
247
|
-
related = Diory.create_from_hash(related_hash)
|
248
|
-
# Add all the relations for freshly created diory
|
249
|
-
if Diory.where(diory_id: related.diory_id).blank?
|
250
|
-
diory.strong_relations << related
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
# Return saved diory
|
256
|
-
diory
|
257
|
-
end
|
258
|
-
|
259
|
-
|
260
|
-
# Fills in all the attributes of Diory from JSON-LD
|
261
|
-
def load_attributes_from_hash(diory_hash)
|
262
|
-
# Load Diory basic attributes from JSONLD
|
263
|
-
@diory_id = diory_hash[Diograph::ATTRIBUTES["diory_id"]]
|
264
|
-
@diory_type = diory_hash[Diograph::ATTRIBUTES["diory_type"]]
|
265
|
-
@name = diory_hash[Diograph::ATTRIBUTES["name"]]
|
266
|
-
@url = diory_hash[Diograph::ATTRIBUTES["url"]]
|
267
|
-
@date = diory_hash[Diograph::ATTRIBUTES["date"]]
|
268
|
-
@gps = diory_hash[Diograph::ATTRIBUTES["gps"]]
|
269
|
-
|
270
|
-
# Define which are basic attributes
|
271
|
-
diograph_attr = [Diograph::ATTRIBUTES["diory_id"], Diograph::ATTRIBUTES["diory_type"], Diograph::ATTRIBUTES["name"], Diograph::ATTRIBUTES["url"], Diograph::ATTRIBUTES["date"], Diograph::ATTRIBUTES["gps"], Diograph::ATTRIBUTES["strong_relations"]]
|
272
|
-
|
273
|
-
# Extract all the other attributes to data
|
274
|
-
# Sorts out the basic attributes from diory_hash
|
275
|
-
diory_hash.select do |key, value|
|
276
|
-
if !diograph_attr.include?(key)
|
277
|
-
@data[key] = value
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
end
|
282
|
-
|
283
|
-
|
284
|
-
# Get a Diograph hash of the Diory and its related diories
|
285
|
-
def to_diograph_hash(include_relations=true)
|
286
|
-
|
287
|
-
diory_hash = {}
|
288
|
-
diory_hash["#{Diograph::ATTRIBUTES['diory_id']}"] = @diory_id
|
289
|
-
diory_hash["#{Diograph::ATTRIBUTES['diory_type']}"] = @diory_type
|
290
|
-
diory_hash["#{Diograph::ATTRIBUTES['name']}"] = @name
|
291
|
-
if !@url.blank?
|
292
|
-
diory_hash["#{Diograph::ATTRIBUTES['url']}"] = @url
|
293
|
-
end
|
294
|
-
if !@date.blank?
|
295
|
-
diory_hash["#{Diograph::ATTRIBUTES['date']}"] = @date
|
296
|
-
end
|
297
|
-
if !@gps.blank?
|
298
|
-
diory_hash["#{Diograph::ATTRIBUTES['gps']}"] = @gps
|
299
|
-
end
|
300
|
-
|
301
|
-
diory_hash["style"] = {"background-color" => "rgb(84,97,112)"}
|
302
|
-
diory_hash["created"] = @created_at
|
303
|
-
diory_hash["modified"] = @updated_at
|
304
|
-
diory_hash["IRI"] = nil
|
305
|
-
|
306
|
-
if !@data.blank?
|
307
|
-
diory_hash.merge!(DiographHash.new_hash_from_diograph(@data))
|
308
|
-
end
|
309
|
-
|
310
|
-
diory_hash["#{Diograph::ATTRIBUTES['strong_relations']}"] = []
|
311
|
-
|
312
|
-
if include_relations
|
313
|
-
|
314
|
-
if !@strong_relations.blank?
|
315
|
-
@strong_relations.each do |strong_relation|
|
316
|
-
diory_hash["#{Diograph::ATTRIBUTES['strong_relations']}"] << to_related_hash(strong_relation.diory_id, @strong_relations.index(strong_relation) + 1)
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
if !@weak_relations.blank?
|
321
|
-
@weak_relations.each do |weak_relation|
|
322
|
-
diory_hash["#{Diograph::ATTRIBUTES['strong_relations']}"] << to_related_hash(weak_relation.diory_id, @weak_relations.index(weak_relation) + 1)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
end
|
327
|
-
|
328
|
-
diory_hash
|
329
|
-
|
330
|
-
end
|
331
|
-
|
332
|
-
|
333
|
-
def to_related_hash(diory_id, order)
|
334
|
-
related_hash = {}
|
335
|
-
related_hash["diory"] = { Diograph::ATTRIBUTES["diory_id"] => diory_id }
|
336
|
-
related_hash["order"] = order
|
337
|
-
related_hash["position"] = {"width" => "25%", "padding-bottom" => "15%"}
|
338
|
-
related_hash
|
339
|
-
end
|
340
|
-
|
341
|
-
|
342
|
-
def to_diograph
|
343
|
-
Diograph.to_diograph(self.to_diograph_hash)
|
344
|
-
end
|
345
|
-
|
346
|
-
|
347
|
-
end
|
348
|
-
|
349
|
-
|
1
|
+
require 'JSON'
|
2
|
+
|
3
|
+
class Diograph
|
4
|
+
|
5
|
+
def self.create_from_room(room)
|
6
|
+
dg = {
|
7
|
+
name: room.name,
|
8
|
+
roomID: room.room_id,
|
9
|
+
created: room.created,
|
10
|
+
modified: room.modified,
|
11
|
+
diories: room.diories.map{|d| create_from_diory(d)}
|
12
|
+
}
|
13
|
+
return JSON.parse dg.to_json # stringify keys
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create_from_diory(diory, include_connections=true)
|
17
|
+
dg = {
|
18
|
+
ID: diory.diory_id,
|
19
|
+
name: diory.name,
|
20
|
+
type: diory.diory_type,
|
21
|
+
created: diory.created,
|
22
|
+
modified: diory.modified,
|
23
|
+
date: diory.date,
|
24
|
+
address: diory.address,
|
25
|
+
background: diory.background
|
26
|
+
}
|
27
|
+
if include_connections
|
28
|
+
dg[:connections] = {}
|
29
|
+
diory.connected_diories.map do |d|
|
30
|
+
dg[:connections][d.diory_id] = {}
|
31
|
+
dg[:connections][d.diory_id]["roomID"] = d.room.room_id
|
32
|
+
dg[:connections][d.diory_id]["diory"] = create_from_diory(d, false)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
return JSON.parse dg.to_json # stringify keys
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.is_equal(diograph1, diograph2)
|
39
|
+
one = diograph1["diories"].sort_by{|d| d["ID"]} unless diograph1.nil?
|
40
|
+
two = diograph2["diories"].sort_by{|d| d["ID"]} unless diograph2.nil?
|
41
|
+
one == two
|
42
|
+
end
|
350
43
|
|
351
44
|
end
|
metadata
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diograph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- jvalanen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Library to deal with diographs in Personal Web applications
|
14
14
|
email: jouni.alanen@iki.fi
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/diograph.rb
|
20
|
-
homepage: http://
|
20
|
+
homepage: http://rubygems.org/gems/diograph
|
21
21
|
licenses: []
|
22
22
|
metadata: {}
|
23
23
|
post_install_message:
|
@@ -39,5 +39,5 @@ rubyforge_project:
|
|
39
39
|
rubygems_version: 2.2.2
|
40
40
|
signing_key:
|
41
41
|
specification_version: 4
|
42
|
-
summary:
|
42
|
+
summary: Library to deal with diographs in Personal Web applications
|
43
43
|
test_files: []
|