rdf-microdata 0.2.3.1 → 0.2.4

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.
data/README CHANGED
@@ -85,7 +85,7 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
85
85
 
86
86
  * gregg@kellogg-assoc.com
87
87
  * <http://rubygems.org/rdf-microdata>
88
- * <http://github.com/gkellogg/rdf-microdata>
88
+ * <http://github.com/ruby-rdf/rdf-microdata>
89
89
  * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
90
90
 
91
91
  [RDF.rb]: http://rdf.rubyforge.org/
@@ -94,4 +94,4 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
94
94
  [PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
95
95
  [Microdata]: http://dev.w3.org/html5/md/Overview.html "HTML Microdata"
96
96
  [Microdata RDF]: https://dvcs.w3.org/hg/htmldata/raw-file/default/microdata-rdf/index.html "Microdata to RDF"
97
- [Microdata doc]: http://rubydoc.info/github/gkellogg/rdf-microdata/frames
97
+ [Microdata doc]: http://rubydoc.info/github/ruby-rdf/rdf-microdata/frames
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3.1
1
+ 0.2.4
data/etc/registry.json CHANGED
@@ -31,9 +31,5 @@
31
31
  "properties": {
32
32
  "categories": {"multipleValues": "list"}
33
33
  }
34
- },
35
- "http://n.whatwg.org/work": {
36
- "propertyURI": "contextual",
37
- "multipleValues": "list"
38
34
  }
39
35
  }
@@ -45,15 +45,21 @@ module RDF::Microdata
45
45
  ##
46
46
  # Initialize the registry from a URI or file path
47
47
  #
48
- # @param [Hash] json
49
- def self.load_registry(json)
48
+ # @param [String] registry_uri
49
+ def self.load_registry(registry_uri)
50
+ return if @registry_uri == registry_uri
51
+
52
+ json = RDF::Util::File.open_file(registry_uri) { |f| JSON.load(f) }
53
+
50
54
  @prefixes = {}
51
55
  json.each do |prefix, elements|
56
+ next unless elements.is_a?(Hash)
52
57
  propertyURI = elements.fetch("propertyURI", "vocabulary").to_sym
53
58
  multipleValues = elements.fetch("multipleValues", "unordered").to_sym
54
59
  properties = elements.fetch("properties", {})
55
60
  @prefixes[prefix] = Registry.new(prefix, propertyURI, multipleValues, properties)
56
61
  end
62
+ @registry_uri = registry_uri
57
63
  end
58
64
 
59
65
  ##
@@ -99,26 +105,30 @@ module RDF::Microdata
99
105
  # @return [RDF::URI]
100
106
  def predicateURI(name, ec)
101
107
  u = RDF::URI(name)
108
+ # 1) If _name_ is an _absolute URL_, return _name_ as a _URI reference_
102
109
  return u if u.absolute?
103
110
 
104
111
  n = frag_escape(name)
105
112
  if ec[:current_type].nil?
113
+ # 2) If current type from context is null, there can be no current vocabulary.
114
+ # Return the URI reference that is the document base with its fragment set to
115
+ # the fragment-escaped value of name
106
116
  u = RDF::URI(ec[:document_base].to_s)
107
117
  u.fragment = frag_escape(name)
108
118
  u
109
119
  elsif @scheme == :vocabulary
110
- # If scheme is vocabulary return the URI reference constructed by appending the fragment escaped value of name
111
- # to current vocabulary, separated by a U+0023 NUMBER SIGN character (#) unless the current vocabulary ends
112
- # with either a U+0023 NUMBER SIGN character (#) or SOLIDUS U+002F (/).
120
+ # 4) If scheme is vocabulary return the URI reference constructed by appending the fragment escaped value of name
121
+ # to current vocabulary, separated by a U+0023 NUMBER SIGN character (#) unless the current vocabulary ends
122
+ # with either a U+0023 NUMBER SIGN character (#) or SOLIDUS U+002F (/).
113
123
  RDF::URI(@property_base + n)
114
124
  else # @scheme == :contextual
115
- if ec[:current_type].to_s.index(@property_base) == 0
116
- # return the concatenation of s, a U+002E FULL STOP character (.) and the fragment-escaped value of name.
117
- RDF::URI(@property_base + '.' + n)
125
+ if ec[:current_name].to_s.index(@property_base) == 0
126
+ # 5.2) return the concatenation of s, a U+002E FULL STOP character (.) and the fragment-escaped value of name.
127
+ RDF::URI(ec[:current_name] + '.' + n)
118
128
  else
119
- # return the concatenation of http://www.w3.org/ns/md?type=, the fragment-escaped value of s,
129
+ # 5.3) return the concatenation of http://www.w3.org/ns/md?type=, the fragment-escaped value of current type,
120
130
  # the string &prop=, and the fragment-escaped value of name
121
- RDF::URI(@property_base + frag_escape(ec[:current_type]) + '?prop=' + n)
131
+ RDF::URI(@property_base + frag_escape(ec[:current_type]) + '&prop=' + n)
122
132
  end
123
133
  end
124
134
  end
@@ -215,14 +225,11 @@ module RDF::Microdata
215
225
  add_debug(@doc, "library = #{@library}")
216
226
 
217
227
  # Load registry
218
- unless Registry.loaded?
219
- registry = options[:registry_uri] || DEFAULT_REGISTRY
220
- begin
221
- json = RDF::Util::File.open_file(registry) { |f| JSON.load(f) }
222
- rescue JSON::ParserError => e
223
- raise RDF::ReaderError, "Failed to parse registry: #{e.message}"
224
- end
225
- Registry.load_registry(json)
228
+ begin
229
+ registry_uri = options[:registry_uri] || DEFAULT_REGISTRY
230
+ Registry.load_registry(registry_uri)
231
+ rescue JSON::ParserError => e
232
+ raise RDF::ReaderError, "Failed to parse registry: #{e.message}"
226
233
  end
227
234
 
228
235
  if block_given?
@@ -381,70 +388,77 @@ module RDF::Microdata
381
388
  add_triple(item, subject, RDF.type, t)
382
389
  end
383
390
 
384
- # 5) If type is not an absolute URL, set it to current type from the Evaluation Context if not empty.
391
+ # 5) If type is an absolute URL, set current name in evaluation context to null.
392
+ ec[:current_name] = nil if type
393
+
394
+ # 6) Otherwise, set type to current type from the Evaluation Context if not empty.
385
395
  type ||= ec[:current_type]
386
- add_debug(item) {"gentrips(5): type=#{type.inspect}"}
396
+ add_debug(item) {"gentrips(6): type=#{type.inspect}"}
387
397
 
388
- # 6) If the registry contains a URI prefix that is a character for character match of type up to the length of the
398
+ # 7) If the registry contains a URI prefix that is a character for character match of type up to the length of the
389
399
  # URI prefix, set vocab as that URI prefix
390
400
  vocab = Registry.find(type)
391
401
 
392
- # 7) Otherwise, if type is not empty, construct vocab by removing everything following the last
393
- # SOLIDUS U+002F ("/") or NUMBER SIGN U+0023 ("#") from type.
402
+ # 8) Otherwise, if type is not empty, construct vocab by removing everything following the last
403
+ # SOLIDUS U+002F ("/") or NUMBER SIGN U+0023 ("#") from the path component of type.
394
404
  vocab ||= begin
395
405
  type_vocab = type.to_s.sub(/([\/\#])[^\/\#]*$/, '\1')
396
- add_debug(item) {"gentrips(7): typtype_vocab=#{type_vocab.inspect}"}
406
+ add_debug(item) {"gentrips(8): type_vocab=#{type_vocab.inspect}"}
397
407
  Registry.new(type_vocab) # if type
398
408
  end
399
409
 
400
- # 8) Update evaluation context setting current vocabulary to vocab.
410
+ # 9) Update evaluation context setting current vocabulary to vocab.
401
411
  ec[:current_vocabulary] = vocab
402
412
 
403
- # 9) Set property list to an empty mapping between properties and one or more ordered values as established below.
413
+ # 10) Set property list to an empty mapping between properties and one or more ordered values as established below.
404
414
  property_list = {}
405
415
 
406
- # 10. For each element _element_ that has one or more property names and is one of the
416
+ # 11. For each element _element_ that has one or more property names and is one of the
407
417
  # properties of the item _item_, in the order those elements are given by the algorithm
408
418
  # that returns the properties of an item, run the following substep:
409
419
  props = item_properties(item)
410
- # 10.1. For each name name in element's property names, run the following substeps:
420
+ # 11.1. For each name name in element's property names, run the following substeps:
411
421
  props.each do |element|
412
422
  element.attribute('itemprop').to_s.split(' ').compact.each do |name|
413
- add_debug(element) {"gentrips(10.1): name=#{name.inspect}, type=#{type}"}
414
- # Let context be a copy of evaluation context with current type set to type and current vocabulary set to vocab.
423
+ add_debug(item) {"gentrips(11.1): name=#{name.inspect}, type=#{type}"}
424
+ # 11.1.1) Let context be a copy of evaluation context with current type set to type and current vocabulary set to vocab.
415
425
  ec_new = ec.merge({:current_type => type, :current_vocabulary => vocab})
416
426
 
427
+ # 11.1.2) Let predicate be the result of generate predicate URI using context and name. Update context by setting current name to predicate.
417
428
  predicate = vocab.predicateURI(name, ec_new)
418
429
  ec_new[:current_name] = predicate
419
- add_debug(element) {"gentrips(10.1.2): predicate=#{predicate}"}
430
+ add_debug(item) {"gentrips(11.1.2): predicate=#{predicate}"}
420
431
 
421
- # 10.1.3) Let value be the property value of element.
432
+ # 11.1.3) Let value be the property value of element.
422
433
  value = property_value(element)
423
- add_debug(element) {"gentrips(10.1.3) value=#{value.inspect}"}
434
+ add_debug(item) {"gentrips(11.1.3) value=#{value.inspect}"}
424
435
 
425
- # 10.1.4) If value is an item, then generate the triples for value using a copy of evaluation context with
426
- # current type set to type. Replace value by the subject returned from those steps.
436
+ # 11.1.4) If value is an item, then generate the triples for value context.
437
+ # Replace value by the subject returned from those steps.
427
438
  if value.is_a?(Hash)
428
439
  value = generate_triples(element, ec_new)
429
- add_debug(element) {"gentrips(10.1.4): value=#{value.inspect}"}
440
+ add_debug(item) {"gentrips(11.1.4): value=#{value.inspect}"}
430
441
  end
431
442
 
443
+ # 11.1.5) Add value to property list for predicate
432
444
  property_list[predicate] ||= []
433
445
  property_list[predicate] << value
434
446
  end
435
447
  end
436
448
 
437
- # 11) For each predicate in property list
449
+ # 12) For each predicate in property list
438
450
  property_list.each do |predicate, values|
439
- generatePropertyValues(item, subject, predicate, values, ec)
451
+ generatePropertyValues(item, subject, predicate, values)
440
452
  end
441
453
 
442
454
  subject
443
455
  end
444
456
 
445
- def generatePropertyValues(element, subject, predicate, values, ec)
446
- registry = ec[:current_vocabulary]
447
- if registry.as_list(predicate)
457
+ def generatePropertyValues(element, subject, predicate, values)
458
+ # If the registry contains a URI prefix that is a character for character match of predicate up to the length
459
+ # of the URI prefix, set vocab as that URI prefix. Otherwise set vocab to null
460
+ registry = Registry.find(predicate)
461
+ if registry && registry.as_list(predicate)
448
462
  value = generateRDFCollection(element, values)
449
463
  add_triple(element, subject, predicate, value)
450
464
  else
@@ -2,4 +2,6 @@ module RDF
2
2
  class MD < Vocabulary("http://www.w3.org/ns/md#"); end
3
3
  class Schema < Vocabulary("http://schema.org/"); end
4
4
  class XHV < Vocabulary("http://www.w3.org/1999/xhtml/vocab#"); end
5
+ class HCard < Vocabulary("http://microformats.org/profile/hcard#"); end
6
+ class HCalendar < Vocabulary("http://microformats.org/profile/hcalendar"); end
5
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-microdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3.1
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-18 00:00:00.000000000 Z
13
+ date: 2012-05-14 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf
17
- requirement: &2156220160 !ruby/object:Gem::Requirement
17
+ requirement: &70185697963060 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.3.4
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2156220160
25
+ version_requirements: *70185697963060
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: json
28
- requirement: &2156191060 !ruby/object:Gem::Requirement
28
+ requirement: &70185697962540 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.6.1
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2156191060
36
+ version_requirements: *70185697962540
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rdf-xsd
39
- requirement: &2156190000 !ruby/object:Gem::Requirement
39
+ requirement: &70185697962060 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.3.4
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2156190000
47
+ version_requirements: *70185697962060
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: htmlentities
50
- requirement: &2156188860 !ruby/object:Gem::Requirement
50
+ requirement: &70185697961580 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 4.3.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *2156188860
58
+ version_requirements: *70185697961580
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: nokogiri
61
- requirement: &2156184760 !ruby/object:Gem::Requirement
61
+ requirement: &70185697960380 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.5.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2156184760
69
+ version_requirements: *70185697960380
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: equivalent-xml
72
- requirement: &2156183840 !ruby/object:Gem::Requirement
72
+ requirement: &70185697959860 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 0.2.8
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2156183840
80
+ version_requirements: *70185697959860
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: yard
83
- requirement: &2156176780 !ruby/object:Gem::Requirement
83
+ requirement: &70185697959400 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,21 +88,32 @@ dependencies:
88
88
  version: 0.6.0
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2156176780
91
+ version_requirements: *70185697959400
92
+ - !ruby/object:Gem::Dependency
93
+ name: spira
94
+ requirement: &70185697958860 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: 0.0.12
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *70185697958860
92
103
  - !ruby/object:Gem::Dependency
93
104
  name: rspec
94
- requirement: &2156173520 !ruby/object:Gem::Requirement
105
+ requirement: &70185697958300 !ruby/object:Gem::Requirement
95
106
  none: false
96
107
  requirements:
97
108
  - - ! '>='
98
109
  - !ruby/object:Gem::Version
99
- version: 2.5.0
110
+ version: 2.8.0
100
111
  type: :development
101
112
  prerelease: false
102
- version_requirements: *2156173520
113
+ version_requirements: *70185697958300
103
114
  - !ruby/object:Gem::Dependency
104
115
  name: rdf-spec
105
- requirement: &2156171040 !ruby/object:Gem::Requirement
116
+ requirement: &70185697957720 !ruby/object:Gem::Requirement
106
117
  none: false
107
118
  requirements:
108
119
  - - ! '>='
@@ -110,10 +121,10 @@ dependencies:
110
121
  version: 0.3.4
111
122
  type: :development
112
123
  prerelease: false
113
- version_requirements: *2156171040
124
+ version_requirements: *70185697957720
114
125
  - !ruby/object:Gem::Dependency
115
126
  name: rdf-turtle
116
- requirement: &2156170340 !ruby/object:Gem::Requirement
127
+ requirement: &70185697957140 !ruby/object:Gem::Requirement
117
128
  none: false
118
129
  requirements:
119
130
  - - ! '>='
@@ -121,10 +132,10 @@ dependencies:
121
132
  version: 0.1.0
122
133
  type: :development
123
134
  prerelease: false
124
- version_requirements: *2156170340
135
+ version_requirements: *70185697957140
125
136
  - !ruby/object:Gem::Dependency
126
137
  name: rdf-isomorphic
127
- requirement: &2156162920 !ruby/object:Gem::Requirement
138
+ requirement: &70185697956660 !ruby/object:Gem::Requirement
128
139
  none: false
129
140
  requirements:
130
141
  - - ! '>='
@@ -132,7 +143,7 @@ dependencies:
132
143
  version: 0.3.4
133
144
  type: :development
134
145
  prerelease: false
135
- version_requirements: *2156162920
146
+ version_requirements: *70185697956660
136
147
  description: Microdata reader for Ruby.
137
148
  email: public-rdf-ruby@w3.org
138
149
  executables: []
@@ -152,7 +163,7 @@ files:
152
163
  - lib/rdf/microdata.rb
153
164
  - etc/doap.html
154
165
  - etc/registry.json
155
- homepage: http://github.com/gkellogg/rdf-microdata
166
+ homepage: http://github.com/ruby-rdf/rdf-microdata
156
167
  licenses:
157
168
  - Public Domain
158
169
  post_install_message:
@@ -173,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
184
  version: '0'
174
185
  requirements: []
175
186
  rubyforge_project: rdf-microdata
176
- rubygems_version: 1.8.10
187
+ rubygems_version: 1.8.17
177
188
  signing_key:
178
189
  specification_version: 3
179
190
  summary: Microdata reader for Ruby.