rdf-rdfxml 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a008b5ac397b0ac5cc342613446159218c29f9d
4
- data.tar.gz: 36447993bfa7903128d7a7c34a899c74fae497ca
3
+ metadata.gz: d3ada350c5677d2a143dcbd5af7e789f22786b11
4
+ data.tar.gz: 5e6a3a327cd63768c241c0f8c576d66846b83d1f
5
5
  SHA512:
6
- metadata.gz: e666105b18bbeea340dc20da88f0cc5cf4526a6462612c576c8dfca2506062b4dc73c29b871d1a3a68127e73ab7f5b02b8412a7c6498e444a5051dc931ff3b39
7
- data.tar.gz: bd87404140762049fc29b21d49373e5d408b9f679ada3ecc9c696652144f4b13e19f48702a5a3e5c9dfd5cb72d24554611fbf4cddbf21c7d18d4161720b4e0bf
6
+ metadata.gz: f467b070afe52055efc33650615d87af8c73212416c2ec0525833b1516f1d32d40453471aa26d597cde600530cd49e3862c3b2088ce54b63eb62714819eb59e1
7
+ data.tar.gz: ebfa2248b95722a2702c0b0c2742ec93be999c9846263dd336dadefb10596ac3cd1d57ff2d72b4854cc74820f8e7ea871f538b440791e79b5132fd0b3a161d85
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.1.3
@@ -5,14 +5,6 @@ class Nokogiri::XML::Node
5
5
  ns = self.namespace ? self.namespace.href : RDF::XML.to_s
6
6
  RDF::URI.intern(ns + self.node_name)
7
7
  end
8
-
9
- def display_path
10
- @display_path ||= case self
11
- when Nokogiri::XML::Document then ""
12
- when Nokogiri::XML::Element then parent ? "#{parent.display_path}/#{name}" : name
13
- when Nokogiri::XML::Attr then "#{parent && parent.display_path}@#{name}"
14
- end
15
- end
16
8
 
17
9
  alias_method :attribute_with_ns_without_ffi_null, :attribute_with_ns
18
10
  ##
@@ -23,6 +23,15 @@ module RDF::RDFXML
23
23
  @parent = parent
24
24
  end
25
25
 
26
+ # Create a new element child of an existing node
27
+ def create_node(name, children)
28
+ native = ::Nokogiri::XML::Element.new(name, @node)
29
+ children.each do |c|
30
+ native.add_child(c.node)
31
+ end
32
+ NodeProxy.new(native, self)
33
+ end
34
+
26
35
  ##
27
36
  # Element language
28
37
  #
@@ -124,6 +133,10 @@ module RDF::RDFXML
124
133
  end
125
134
  end
126
135
 
136
+ def at_xpath(*args)
137
+ xpath(*args).first
138
+ end
139
+
127
140
  # For jRuby, there is a bug that prevents the namespace from being set on an element
128
141
  if RUBY_PLATFORM == "java"
129
142
  def add_namespace(prefix, href)
@@ -151,6 +164,8 @@ module RDF::RDFXML
151
164
  RDF::URI.intern(ns + self.node_name)
152
165
  end
153
166
 
167
+ def to_s; @node.to_s; end
168
+
154
169
  ##
155
170
  # Proxy for everything else to @node
156
171
  def method_missing(method, *args)
@@ -1,3 +1,5 @@
1
+ require 'htmlentities'
2
+
1
3
  module RDF::RDFXML
2
4
  class Reader < RDF::Reader
3
5
  ##
@@ -13,6 +15,11 @@ module RDF::RDFXML
13
15
  :rexml
14
16
  end
15
17
 
18
+ # For Attribute namespaces
19
+ Namespace = Struct.new(:href, :prefix) do
20
+ def to_s; href; end
21
+ end
22
+
16
23
  # Proxy class to implement uniform element accessors
17
24
  class NodeProxy
18
25
  attr_reader :node
@@ -21,6 +28,28 @@ module RDF::RDFXML
21
28
  def initialize(node, parent = nil)
22
29
  @node = node
23
30
  @parent = parent
31
+ @parent = NodeProxy.new(node.parent) if @parent.nil? &&
32
+ node.respond_to?(:parent) &&
33
+ node.parent &&
34
+ !node.parent.is_a?(::REXML::Document)
35
+ end
36
+
37
+ # Create a new element child of an existing node
38
+ def create_node(name, children)
39
+ native = ::REXML::Element.new(name, @node)
40
+ children.each do |c|
41
+ case c.node
42
+ when ::REXML::Text
43
+ native.add_text(c.node)
44
+ when ::REXML::Element
45
+ native.add_element(c.node)
46
+ when ::REXML::Comment
47
+ # Skip comments
48
+ else
49
+ raise "Unexpected child node type: #{c.node.class}"
50
+ end
51
+ end
52
+ NodeProxy.new(native, self)
24
53
  end
25
54
 
26
55
  ##
@@ -89,7 +118,15 @@ module RDF::RDFXML
89
118
  end
90
119
  ns_decls
91
120
  end
92
-
121
+
122
+ def namespace
123
+ Namespace.new(@node.namespace, @node.prefix) unless @node.namespace.to_s.empty?
124
+ end
125
+
126
+ def add_namespace(prefix, uri)
127
+ prefix ? !@node.add_namespace(prefix, uri) : @node.add_namespace(uri)
128
+ end
129
+
93
130
  ##
94
131
  # Children of this node
95
132
  #
@@ -115,33 +152,46 @@ module RDF::RDFXML
115
152
  }.join
116
153
  end
117
154
 
118
- ##
119
- # Node type accessors
120
- #
121
- # @return [Boolean]
122
- def element?
123
- @node.is_a?(::REXML::Element)
155
+ def attribute_nodes
156
+ attrs = @node.attributes.dup.keep_if do |name, attr|
157
+ !name.start_with?('xmlns')
158
+ end
159
+ @attribute_nodes ||= (attrs.empty? ? attrs : NodeSetProxy.new(attrs, self))
124
160
  end
125
161
 
126
- def attribute_nodes
127
- @attribute_nodes ||= NodeSetProxy.new(@node.children.select {|n| n.is_a?(::REXML::Attribute)}, self)
162
+ def remove_attribute(key)
163
+ @node.delete_attribute(key)
128
164
  end
129
165
 
130
166
  def xpath(*args)
131
167
  #NodeSetProxy.new(::REXML::XPath.match(@node, path, namespaces), self)
132
168
  ::REXML::XPath.match(@node, *args).map do |n|
133
- # Get node ancestors
134
- parent = n.ancestors.reverse.inject(nil) do |p,node|
135
- NodeProxy.new(node, p)
136
- end
137
169
  NodeProxy.new(n, parent)
138
170
  end
139
171
  end
140
172
 
141
- def elem?
173
+ def at_xpath(*args)
174
+ xpath(*args).first
175
+ end
176
+
177
+ ##
178
+ # Node type accessors
179
+ #
180
+ # @return [Boolean]
181
+ def text?
182
+ @node.is_a?(::REXML::Text)
183
+ end
184
+
185
+ def element?
142
186
  @node.is_a?(::REXML::Element)
143
187
  end
144
188
 
189
+ def blank?
190
+ @node.is_a?(::REXML::Text) && @node.empty?
191
+ end
192
+
193
+ def to_s; @node.to_s; end
194
+
145
195
  ##
146
196
  # Proxy for everything else to @node
147
197
  def method_missing(method, *args)
@@ -166,10 +216,22 @@ module RDF::RDFXML
166
216
  # @yield child
167
217
  # @yieldparam [NodeProxy]
168
218
  def each
169
- @node_set.each do |c|
219
+ @node_set.to_a.each do |c|
170
220
  yield NodeProxy.new(c, parent)
171
221
  end
172
222
  end
223
+
224
+ ##
225
+ # Return selected NodeProxies based on selection
226
+ #
227
+ # @yield child
228
+ # @yieldparam [NodeProxy]
229
+ # @return [Array[NodeProxy]]
230
+ def select
231
+ @node_set.to_a.map {|n| NodeProxy.new(n, parent)}.select do |c|
232
+ yield c
233
+ end
234
+ end
173
235
 
174
236
  ##
175
237
  # Proxy for everything else to @node_set
@@ -188,7 +188,7 @@ module RDF::RDFXML
188
188
  add_debug(root, "base_uri: #{base_uri.inspect}")
189
189
 
190
190
  rdf_nodes = root.xpath("//rdf:RDF", "rdf" => RDF.to_uri.to_s)
191
- if rdf_nodes.length == 0
191
+ if rdf_nodes.size == 0
192
192
  # If none found, root element may be processed as an RDF Node
193
193
 
194
194
  ec = EvaluationContext.new(base_uri, root, @graph) do |prefix, value|
@@ -207,7 +207,7 @@ module RDF::RDFXML
207
207
  prefix(prefix, value)
208
208
  end
209
209
  node.children.each {|el|
210
- next unless el.elem?
210
+ next unless el.element?
211
211
  raise "el must be a proxy not a #{el.class}" unless el.is_a?(@implementation::NodeProxy)
212
212
  new_ec = ec.clone(el) do |prefix, value|
213
213
  prefix(prefix, value)
@@ -316,7 +316,7 @@ module RDF::RDFXML
316
316
  li_counter = 0 # this will increase for each li we iterate through
317
317
  el.children.each do |child|
318
318
  raise "child must be a proxy not a #{child.class}" unless child.is_a?(@implementation::NodeProxy)
319
- next unless child.elem?
319
+ next unless child.element?
320
320
  child_ec = ec.clone(child) do |prefix, value|
321
321
  prefix(prefix, value)
322
322
  end
@@ -338,7 +338,7 @@ module RDF::RDFXML
338
338
  raise "element node must be a proxy not a #{node.class}" unless node.is_a?(@implementation::NodeProxy)
339
339
  end
340
340
 
341
- if element_nodes.length > 1
341
+ if element_nodes.size > 1
342
342
  element_nodes.each do |node|
343
343
  add_debug(child) {" node: #{node.to_s}"}
344
344
  end
@@ -399,7 +399,7 @@ module RDF::RDFXML
399
399
  add_debug(child) {"nodeID: #{nodeID}"} if nodeID
400
400
  add_debug(child) {"id: #{id}"} if id
401
401
 
402
- if attrs.empty? && datatype.nil? && parseType.nil? && element_nodes.length == 1
402
+ if attrs.empty? && datatype.nil? && parseType.nil? && element_nodes.size == 1
403
403
  # Production resourcePropertyElt
404
404
 
405
405
  new_ec = child_ec.clone(nil) do |prefix, value|
@@ -410,7 +410,7 @@ module RDF::RDFXML
410
410
  add_debug(child) {"resourcePropertyElt: #{node_path(new_node_element)}"}
411
411
  new_subject = nodeElement(new_node_element, new_ec)
412
412
  add_triple(child, subject, predicate, new_subject)
413
- elsif attrs.empty? && parseType.nil? && element_nodes.length == 0 && text_nodes.length > 0
413
+ elsif attrs.empty? && parseType.nil? && element_nodes.size == 0 && text_nodes.size > 0
414
414
  # Production literalPropertyElt
415
415
  add_debug(child, "literalPropertyElt")
416
416
 
@@ -448,9 +448,9 @@ module RDF::RDFXML
448
448
  # c
449
449
  # end-element()
450
450
  add_debug(child, "compose new sequence with rdf:Description")
451
- node = child.clone
452
- node.attributes.keys.each {|a| node.remove_attribute(a)}
453
- node.node_name = "Description"
451
+ #child.clone
452
+ #node.attributes.keys.each {|a| node.remove_attribute(a)}
453
+ node = el.create_node("Description", child.children)
454
454
  node.add_namespace(nil, RDF.to_uri.to_s)
455
455
  add_debug(node) { "uri: #{node.uri}, namespace: #{node.namespace.inspect}"}
456
456
  new_ec = child_ec.clone(nil, :subject => n) do |prefix, value|
@@ -518,7 +518,7 @@ module RDF::RDFXML
518
518
  rescue ArgumentError => e
519
519
  add_error(child, e.message)
520
520
  end
521
- elsif text_nodes.length == 0 && element_nodes.length == 0
521
+ elsif text_nodes.size == 0 && element_nodes.size == 0
522
522
  # Production emptyPropertyElt
523
523
  add_debug(child, "emptyPropertyElt")
524
524
 
@@ -1,4 +1,3 @@
1
- require 'nokogiri' # FIXME: Implement using different modules as in RDF::TriX
2
1
  require 'rdf/rdfa'
3
2
 
4
3
  module RDF::RDFXML
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-rdfxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-25 00:00:00.000000000 Z
12
+ date: 2014-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -66,19 +66,19 @@ dependencies:
66
66
  - !ruby/object:Gem::Version
67
67
  version: '1.1'
68
68
  - !ruby/object:Gem::Dependency
69
- name: equivalent-xml
69
+ name: htmlentities
70
70
  requirement: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0.2'
75
- type: :development
74
+ version: '4.3'
75
+ type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0.2'
81
+ version: '4.3'
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: open-uri-cached
84
84
  requirement: !ruby/object:Gem::Requirement