rdf-microdata 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/rdf/microdata/reader.rb +18 -11
  3. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -22,8 +22,14 @@ module RDF::Microdata
22
22
  ##
23
23
  # Returns the base URI determined by this reader.
24
24
  #
25
- # @attr [RDF::URI]
26
- attr_reader :base_uri
25
+ # @example
26
+ # reader.prefixes[:dc] #=> RDF::URI('http://purl.org/dc/terms/')
27
+ #
28
+ # @return [Hash{Symbol => RDF::URI}]
29
+ # @since 0.3.0
30
+ def base_uri
31
+ @options[:base_uri]
32
+ end
27
33
 
28
34
  ##
29
35
  # Initializes the Microdata reader instance.
@@ -63,7 +69,8 @@ module RDF::Microdata
63
69
  # Otherwise, default is utf-8
64
70
  options[:encoding] ||= 'utf-8'
65
71
 
66
- Nokogiri::HTML.parse(input, @base_uri.to_s, options[:encoding])
72
+ add_debug(nil, "base_uri: #{base_uri}")
73
+ Nokogiri::HTML.parse(input, base_uri.to_s, options[:encoding])
67
74
  end
68
75
 
69
76
  if (@doc.nil? || @doc.root.nil?)
@@ -87,7 +94,7 @@ module RDF::Microdata
87
94
  @callback = block
88
95
 
89
96
  # parse
90
- parse_whole_document(@doc, @base_uri)
97
+ parse_whole_document(@doc, base_uri)
91
98
  end
92
99
 
93
100
  ##
@@ -114,7 +121,7 @@ module RDF::Microdata
114
121
 
115
122
  # Figure out the document path, if it is a Nokogiri::XML::Element or Attribute
116
123
  def node_path(node)
117
- "<#{@base_uri}>" + case node
124
+ "<#{base_uri}>" + case node
118
125
  when Nokogiri::XML::Node then node.display_path
119
126
  else node.to_s
120
127
  end
@@ -158,7 +165,7 @@ module RDF::Microdata
158
165
  if (base)
159
166
  # Strip any fragment from base
160
167
  base = base.to_s.split('#').first
161
- base = @base_uri = uri(base)
168
+ base = options[:base_uri] = uri(base)
162
169
  add_debug(base_el, "parse_whole_doc: base='#{base}'")
163
170
  else
164
171
  base = RDF::URI("")
@@ -267,7 +274,7 @@ module RDF::Microdata
267
274
  subject = if memory.include?(item)
268
275
  memory[item][:subject]
269
276
  elsif item.has_attribute?('itemid')
270
- u = uri(item.attribute('itemid'))
277
+ u = uri(item.attribute('itemid'), item.base || base_uri)
271
278
  end || RDF::Node.new
272
279
  memory[item] ||= {}
273
280
 
@@ -448,18 +455,18 @@ module RDF::Microdata
448
455
  ##
449
456
  #
450
457
  def property_value(element)
451
- add_debug(element, "property_value(#{element.inspect})")
458
+ add_debug(element, "property_value(#{element.inspect}): base #{element.base.inspect}, base_uri: #{base_uri.inspect}")
452
459
  case
453
460
  when element.has_attribute?('itemscope')
454
461
  {}
455
462
  when element.name == 'meta'
456
463
  element.attribute('content').to_s
457
464
  when %w(audio embed iframe img source track video).include?(element.name)
458
- uri(element.attribute('src'), element.base)
465
+ uri(element.attribute('src'), element.base || base_uri)
459
466
  when %w(a area link).include?(element.name)
460
- uri(element.attribute('href'), element.base)
467
+ uri(element.attribute('href'), element.base || base_uri)
461
468
  when %w(object).include?(element.name)
462
- uri(element.attribute('data'), element.base)
469
+ uri(element.attribute('data'), element.base || base_uri)
463
470
  when %w(time).include?(element.name) && element.has_attribute?('datetime')
464
471
  # Lexically scan value and assign appropriate type, otherwise, leave untyped
465
472
  v = element.attribute('datetime').to_s
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-microdata
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gregg Kellogg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-12 00:00:00 -07:00
18
+ date: 2011-08-19 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency