json-ld 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,64 +1,50 @@
1
- JSON-LD reader/writer
2
- ==================================
1
+ # JSON-LD reader/writer
3
2
 
4
3
  [JSON-LD][] reader/writer for [RDF.rb][RDF.rb] .
5
4
 
6
- Features
7
- --------
5
+ ## Features
8
6
 
9
7
  JSON::LD parses and serializes [JSON-LD][] into statements or triples.
10
8
 
11
9
  Install with `gem install json-ld`
12
10
 
13
- Examples
14
- --------
11
+ ## Examples
15
12
 
16
13
  require 'rubygems'
17
14
  require 'json/ld'
18
15
 
19
- Documentation
20
- -------------
21
-
22
- <http://rdf.rubyforge.org/json-ld>
16
+ ## Documentation
17
+ Full documentation available on [RubyDoc](http://rubydoc.info/gems/json-ld/0.0.4/file/README)
23
18
 
19
+ ### Principle Classes
24
20
  * {JSON::LD}
21
+ * {JSON::LD::Format}
22
+ * {JSON::LD::Reader}
23
+ * {JSON::LD::Writer}
25
24
 
26
- Dependencies
27
- ------------
28
-
25
+ ##Dependencies
29
26
  * [Ruby](http://ruby-lang.org/) (>= 1.8.7) or (>= 1.8.1 with [Backports][])
30
27
  * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.3)
31
28
  * [JSON](https://rubygems.org/gems/json) (>= 1.5.1)
32
29
 
33
- Installation
34
- ------------
35
-
30
+ ## Installation
36
31
  The recommended installation method is via [RubyGems](http://rubygems.org/).
37
32
  To install the latest official release of the `JSON-LD` gem, do:
38
33
 
39
34
  % [sudo] gem install json-ld
40
35
 
41
- Download
42
- --------
43
-
36
+ ## Download
44
37
  To get a local working copy of the development repository, do:
45
38
 
46
39
  % git clone git://github.com/gkellogg/json-ld.git
47
40
 
48
- Mailing List
49
- ------------
50
-
41
+ ## Mailing List
51
42
  * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
52
43
 
53
- Author
54
- ------
55
-
44
+ ## Author
56
45
  * [Gregg Kellogg](http://github.com/gkellogg) - <http://kellogg-assoc.com/>
57
46
 
58
-
59
- Contributing
60
- ------------
61
-
47
+ ## Contributing
62
48
  * Do your best to adhere to the existing coding conventions and idioms.
63
49
  * Don't use hard tabs, and don't leave trailing whitespace on any line.
64
50
  * Do document every method you add using [YARD][] annotations. Read the
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.6
@@ -31,4 +31,73 @@ module RDF
31
31
  query(:subject => subject, :predicate => RDF.type).map {|st| st.object}
32
32
  end
33
33
  end
34
+ end
35
+
36
+ if RUBY_VERSION < "1.9"
37
+ class InsertOrderPreservingHash < Hash
38
+ include Enumerable
39
+
40
+ def initialize(*args, &block)
41
+ super
42
+ @ordered_keys = []
43
+ end
44
+
45
+ def []=(key, val)
46
+ @ordered_keys << key unless has_key? key
47
+ super
48
+ end
49
+
50
+ def each
51
+ @ordered_keys.each {|k| yield(k, super[k])}
52
+ end
53
+ alias :each_pair :each
54
+
55
+ def each_value
56
+ @ordered_keys.each {|k| yield(super[k])}
57
+ end
58
+
59
+ def each_key
60
+ @ordered_keys.each {|k| yield k}
61
+ end
62
+
63
+ def keys
64
+ @ordered_keys
65
+ end
66
+
67
+ def values
68
+ @ordered_keys.map {|k| super[k]}
69
+ end
70
+
71
+ def clear
72
+ @ordered_keys.clear
73
+ super
74
+ end
75
+
76
+ def delete(k, &block)
77
+ @ordered_keys.delete(k)
78
+ super
79
+ end
80
+
81
+ def reject!
82
+ del = []
83
+ each_pair {|k,v| del << k if yield k,v}
84
+ del.each {|k| delete k}
85
+ del.empty? ? nil : self
86
+ end
87
+
88
+ def delete_if(&block)
89
+ reject!(&block)
90
+ self
91
+ end
92
+
93
+ def merge!(other)
94
+ @ordered_keys += other.instance_variable_get(:@ordered_keys) || other.keys
95
+ super
96
+ self
97
+ end
98
+
99
+ def merge(other)
100
+ self.dup.merge!(other)
101
+ end
102
+ end
34
103
  end
@@ -69,12 +69,21 @@ module JSON::LD
69
69
  # @attr [Hash{RDF::URI => RDF::URI}]
70
70
  attr :coerce, true
71
71
 
72
+ def self.new_hash
73
+ if RUBY_VERSION < "1.9"
74
+ InsertOrderPreservingHash.new
75
+ else
76
+ Hash.new
77
+ end
78
+ end
79
+ def new_hash; self.class.new_hash; end
80
+
72
81
  ##
73
82
  # Return the pre-serialized Hash before turning into JSON
74
83
  #
75
84
  # @return [Hash]
76
85
  def self.hash(*args, &block)
77
- hash = {}
86
+ hash = new_hash
78
87
  self.new(hash, *args, &block)
79
88
  hash
80
89
  end
@@ -164,7 +173,7 @@ module JSON::LD
164
173
  preprocess
165
174
 
166
175
  # Don't generate context for canonical output
167
- json_hash = @options[:canonicalize] ? {} : start_document
176
+ json_hash = @options[:canonicalize] ? new_hash : start_document
168
177
 
169
178
  elements = []
170
179
  order_subjects.each do |subject|
@@ -233,7 +242,7 @@ module JSON::LD
233
242
  # Encode like a subject
234
243
  iri_range?(options[:property]) ?
235
244
  format_uri(value, :position => :subject) :
236
- {:iri => format_uri(value, :position => :subject)}
245
+ {IRI => format_uri(value, :position => :subject)}
237
246
  end
238
247
 
239
248
  add_debug("format_uri(#{options.inspect}, #{value.inspect}) => #{result.inspect}")
@@ -260,11 +269,11 @@ module JSON::LD
260
269
  # @return [Object]
261
270
  def format_literal(literal, options = {})
262
271
  if options[:canonical] || @options[:canonicalize]
263
- return {
264
- :literal => literal.value,
265
- :datatype => (format_uri(literal.datatype, :position => :subject) if literal.has_datatype?),
266
- :language => (literal.language.to_s if literal.has_language?)
267
- }.delete_if {|k,v| v.nil?}
272
+ ret = new_hash
273
+ ret[LITERAL] = literal.value
274
+ ret[DATATYPE] = format_uri(literal.datatype, :position => :subject)if literal.has_datatype?
275
+ ret[LANGUAGE] = literal.language.to_s if literal.has_language?
276
+ return ret.delete_if {|k,v| v.nil?}
268
277
  end
269
278
 
270
279
  case literal
@@ -320,7 +329,7 @@ module JSON::LD
320
329
  # Generate @context
321
330
  # @return [Hash]
322
331
  def start_document
323
- ctx = {}
332
+ ctx = new_hash
324
333
  ctx[BASE] = base_uri.to_s if base_uri
325
334
  ctx[VOCAB] = vocab.to_s if vocab
326
335
 
@@ -334,7 +343,7 @@ module JSON::LD
334
343
  # Coerce
335
344
  add_debug "start_doc: coerce= #{coerce.inspect}"
336
345
  unless coerce == DEFAULT_COERCE
337
- c_h = {}
346
+ c_h = new_hash
338
347
  coerce.keys.sort.each do |k|
339
348
  next if coerce[k] == DEFAULT_COERCE[k] ||
340
349
  coerce[k] == false ||
@@ -357,8 +366,11 @@ module JSON::LD
357
366
  end
358
367
 
359
368
  add_debug "start_doc: context=#{ctx.inspect}"
369
+
360
370
  # Return hash with @context, or empty
361
- ctx.empty? ? {} : {CONTEXT => ctx}
371
+ r = new_hash
372
+ r[CONTEXT] = ctx unless ctx.empty?
373
+ r
362
374
  end
363
375
 
364
376
  # Perform any preprocessing of statements required
@@ -367,7 +379,7 @@ module JSON::LD
367
379
  (@options[:prefixes] || {}).each_pair do |k, v|
368
380
  @iri_to_prefix[v.to_s] = k
369
381
  end
370
- @options[:prefixes] = {} # Will define actual used when matched
382
+ @options[:prefixes] = new_hash # Will define actual used when matched
371
383
 
372
384
  @graph.each {|statement| preprocess_statement(statement)}
373
385
  end
@@ -398,7 +410,7 @@ module JSON::LD
398
410
  # Option contains referencing property, if this is recursive
399
411
  # @return [Hash]
400
412
  def subject(subject, options = {})
401
- defn = {}
413
+ defn = new_hash
402
414
 
403
415
  raise RDF::WriterError, "Illegal use of subject #{subject.inspect}, not supported" unless subject.resource?
404
416
 
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-ld
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease:
5
- version: 0.0.4
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 6
10
+ version: 0.0.6
6
11
  platform: ruby
7
12
  authors:
8
13
  - Gregg Kellogg
@@ -21,6 +26,11 @@ dependencies:
21
26
  requirements:
22
27
  - - ">="
23
28
  - !ruby/object:Gem::Version
29
+ hash: 21
30
+ segments:
31
+ - 0
32
+ - 3
33
+ - 3
24
34
  version: 0.3.3
25
35
  type: :runtime
26
36
  version_requirements: *id001
@@ -32,6 +42,11 @@ dependencies:
32
42
  requirements:
33
43
  - - ">="
34
44
  - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 1
48
+ - 5
49
+ - 1
35
50
  version: 1.5.1
36
51
  type: :runtime
37
52
  version_requirements: *id002
@@ -43,6 +58,11 @@ dependencies:
43
58
  requirements:
44
59
  - - ">="
45
60
  - !ruby/object:Gem::Version
61
+ hash: 7
62
+ segments:
63
+ - 0
64
+ - 6
65
+ - 0
46
66
  version: 0.6.0
47
67
  type: :development
48
68
  version_requirements: *id003
@@ -54,6 +74,11 @@ dependencies:
54
74
  requirements:
55
75
  - - ">="
56
76
  - !ruby/object:Gem::Version
77
+ hash: 27
78
+ segments:
79
+ - 2
80
+ - 5
81
+ - 0
57
82
  version: 2.5.0
58
83
  type: :development
59
84
  version_requirements: *id004
@@ -65,6 +90,11 @@ dependencies:
65
90
  requirements:
66
91
  - - ">="
67
92
  - !ruby/object:Gem::Version
93
+ hash: 23
94
+ segments:
95
+ - 0
96
+ - 3
97
+ - 2
68
98
  version: 0.3.2
69
99
  type: :development
70
100
  version_requirements: *id005
@@ -76,6 +106,11 @@ dependencies:
76
106
  requirements:
77
107
  - - ">="
78
108
  - !ruby/object:Gem::Version
109
+ hash: 21
110
+ segments:
111
+ - 0
112
+ - 3
113
+ - 3
79
114
  version: 0.3.3
80
115
  type: :development
81
116
  version_requirements: *id006
@@ -87,6 +122,11 @@ dependencies:
87
122
  requirements:
88
123
  - - ">="
89
124
  - !ruby/object:Gem::Version
125
+ hash: 27
126
+ segments:
127
+ - 0
128
+ - 3
129
+ - 4
90
130
  version: 0.3.4
91
131
  type: :development
92
132
  version_requirements: *id007
@@ -98,6 +138,9 @@ dependencies:
98
138
  requirements:
99
139
  - - ">="
100
140
  - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
101
144
  version: "0"
102
145
  type: :development
103
146
  version_requirements: *id008
@@ -109,6 +152,9 @@ dependencies:
109
152
  requirements:
110
153
  - - ">="
111
154
  - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
112
158
  version: "0"
113
159
  type: :development
114
160
  version_requirements: *id009
@@ -120,6 +166,9 @@ dependencies:
120
166
  requirements:
121
167
  - - ">="
122
168
  - !ruby/object:Gem::Version
169
+ hash: 3
170
+ segments:
171
+ - 0
123
172
  version: "0"
124
173
  type: :development
125
174
  version_requirements: *id010
@@ -156,17 +205,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
205
  requirements:
157
206
  - - ">="
158
207
  - !ruby/object:Gem::Version
208
+ hash: 53
209
+ segments:
210
+ - 1
211
+ - 8
212
+ - 1
159
213
  version: 1.8.1
160
214
  required_rubygems_version: !ruby/object:Gem::Requirement
161
215
  none: false
162
216
  requirements:
163
217
  - - ">="
164
218
  - !ruby/object:Gem::Version
219
+ hash: 3
220
+ segments:
221
+ - 0
165
222
  version: "0"
166
223
  requirements: []
167
224
 
168
225
  rubyforge_project: json-ld
169
- rubygems_version: 1.6.2
226
+ rubygems_version: 1.5.0
170
227
  signing_key:
171
228
  specification_version: 3
172
229
  summary: JSON-LD reader/writer for Ruby.