rdf-rdfxml 0.3.4 → 0.3.5

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.
@@ -1,29 +1,33 @@
1
- === 0.3.4
1
+ ### 0.3.5
2
+ * RDF.rb 0.3.4 compatibility.
3
+ * Added format detection.
4
+
5
+ ### 0.3.4
2
6
  * Decode XML Entity declarations when parsing.
3
7
 
4
- === 0.3.3.1
8
+ ### 0.3.3.1
5
9
  * JRuby/FFI compatibility updates.
6
10
  * Simplify property value ordering in writer; this was causing unnecessary prefixes to be generated.
7
11
 
8
- === 0.3.3
12
+ ### 0.3.3
9
13
  * Change licensing to UNLICENSE.
10
14
  * Only generate prefix definitions for prefixes actually used within a serialization.
11
15
  * Make sure that only valid QNames are generated in writer.
12
16
 
13
- === 0.3.2.1
17
+ ### 0.3.2.1
14
18
  * Fix collection serialization bug
15
19
  * Assert :xml as a format type (by creating RDF::RDFXML::XML as a sub-class of Format that uses RDFXML::Reader/Writer)
16
20
 
17
- === 0.3.2
21
+ ### 0.3.2
18
22
  * Refactor rdfcore tests using Spira and open-uri-cached.
19
23
  * Improve detection and reporting of attempts to write illegal values.
20
24
 
21
- === 0.3.1
25
+ ### 0.3.1
22
26
  * In writer
23
27
  * fix bug where a serialized subject is output again, when it appears in a collection.
24
28
  * Fix subject ordering.
25
29
 
26
- === 0.3.0
30
+ ### 0.3.0
27
31
  * RDF.rb 0.3.0 compatibility updates
28
32
  * Remove literal_normalization and qname_hacks, add back uri_hacks (until 0.3.0)
29
33
  * Use nil for default namespace
@@ -44,15 +48,15 @@
44
48
  * Add all in-scope namespaces, not just those that seem to be used.
45
49
  * RSpec 2 compatibility
46
50
 
47
- === 0.2.3
51
+ ### 0.2.3
48
52
  * Fixed QName generation in Writer based on RDF/XML Processing recommendations
49
53
 
50
- === 0.2.2.1
54
+ ### 0.2.2.1
51
55
  * Ruby 1.9.2 support.
52
56
  * Added script/tc to run test cases
53
57
  * Mark failing XMLLiteral tests as pending
54
58
 
55
- === 0.2.2
59
+ ### 0.2.2
56
60
  * Fix bug creating datatyped literal where datatype is a string, not an RDF::URI
57
61
  * Added more XMLLiteral tests (fail, until full canonicalization working)
58
62
  * Added RDF_Reader and RDF_Writer behavior expectations
@@ -65,18 +69,18 @@
65
69
  * Handle XMLLiteral when value is a Nokogiri node set.
66
70
  * Ensure URIs are properly RDF Escaped (patch to RDF::NTriples::Writer#format_uri)
67
71
 
68
- === 0.2.1
72
+ ### 0.2.1
69
73
  * Update for RDF 0.2.1
70
74
  * Writer bug fixes:
71
75
  * RDF::Node#identifier => RDF::Node#id
72
76
  * Vocabulary.new(uri) => Vocabulary(uri)
73
77
 
74
- === 0.2.0
78
+ ### 0.2.0
75
79
  * Updates for RDF 0.2.0
76
80
  * Use URI#intern instead of URI#new
77
81
  * Change use of Graph#predicates and Graph#objects to use as enumerables
78
82
 
79
- === 0.0.3
83
+ ### 0.0.3
80
84
  * Added patches for the following:
81
85
  * RDF::Graph#properties
82
86
  * RDF::Graph#seq (Output rdf:Seq elements in order)
@@ -96,12 +100,12 @@
96
100
  * should create <http://foo/bar> from <http://foo/bar#> and ''
97
101
  * Writer test needs Turtle reader
98
102
 
99
- === 0.0.2
103
+ ### 0.0.2
100
104
  * Added specs from RdfContext
101
105
  * Added array_hacks, nokogiri_hacks, and rdf_escape
102
106
  * Fixed most bugs that are not related to the underlying framework.
103
107
  * Specific failing testcases for rdf-isomorphic, RDF::Literaland others need to be constructed and added as issues against those gems.
104
108
  * Removed interal graph in Reader and implement each_triple & each_statement to perform parsing
105
109
 
106
- === 0.0.1
110
+ ### 0.0.1
107
111
  * First port from RdfContext version 0.5.4
@@ -23,11 +23,11 @@ Instantiate a parser and parse source, specifying type and base-URL
23
23
  end
24
24
 
25
25
  ## Dependencies
26
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.1)
26
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.4)
27
27
  * [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.4.4)
28
28
 
29
29
  ## Documentation
30
- Full documentation available on [RubyForge](http://rdf.rubyforge.org/rdfxml)
30
+ Full documentation available on [RubyForge](http://rubydoc.info/github/gkellogg/rdf-rdfxml/master/frames)
31
31
 
32
32
  ### Principle Classes
33
33
  * {RDF::RDFXML}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -26,6 +26,19 @@ module RDF::RDFXML
26
26
 
27
27
  reader { RDF::RDFXML::Reader }
28
28
  writer { RDF::RDFXML::Writer }
29
+
30
+ ##
31
+ # Sample detection to see if it matches RDF/XML (not Microdata or RDFa)
32
+ #
33
+ # Use a text sample to detect the format of an input file. Sub-classes implement
34
+ # a matcher sufficient to detect probably format matches, including disambiguating
35
+ # between other similar formats.
36
+ #
37
+ # @param [String] sample Beginning several bytes (~ 1K) of input.
38
+ # @return [Boolean]
39
+ def self.detect(sample)
40
+ sample.match(/<(\w+:)?(RDF)/)
41
+ end
29
42
  end
30
43
 
31
44
  # Aliases for this format
@@ -137,7 +137,6 @@ module RDF::RDFXML
137
137
  else
138
138
  Nokogiri::XML.parse(input, @base_uri.to_s) do |config|
139
139
  config.noent
140
- config.strict if options[:validate]
141
140
  end
142
141
  end
143
142
 
@@ -229,9 +228,12 @@ module RDF::RDFXML
229
228
 
230
229
  # Add debug event to debug array, if specified
231
230
  #
232
- # @param [XML Node, any] node:: XML Node or string for showing context
231
+ # @param [Nokogiri::XML::Node, #to_s] node:: XML Node or string for showing context
233
232
  # @param [String] message::
234
- def add_debug(node, message)
233
+ # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
234
+ def add_debug(node, message = "")
235
+ return unless ::RDF::RDFXML.debug? || @debug
236
+ message = message + yield if block_given?
235
237
  puts "#{node_path(node)}: #{message}" if ::RDF::RDFXML::debug?
236
238
  @debug << "#{node_path(node)}: #{message}" if @debug.is_a?(Array)
237
239
  end
@@ -246,7 +248,7 @@ module RDF::RDFXML
246
248
  # @raise [RDF::ReaderError]:: Checks parameter types and raises if they are incorrect if validating.
247
249
  def add_triple(node, subject, predicate, object)
248
250
  statement = RDF::Statement.new(subject, predicate, object)
249
- add_debug(node, "statement: #{statement}")
251
+ add_debug(node) {"statement: #{statement}"}
250
252
  @callback.call(statement)
251
253
  end
252
254
 
@@ -260,9 +262,9 @@ module RDF::RDFXML
260
262
  # subject
261
263
  subject = ec.subject || parse_subject(el, ec)
262
264
 
263
- add_debug(el, "nodeElement, ec: #{ec.inspect}")
264
- add_debug(el, "nodeElement, el: #{el.uri}")
265
- add_debug(el, "nodeElement, subject: #{subject.nil? ? 'nil' : subject.to_s}")
265
+ add_debug(el) {"nodeElement, ec: #{ec.inspect}"}
266
+ add_debug(el) {"nodeElement, el: #{el.uri}"}
267
+ add_debug(el) {"nodeElement, subject: #{subject.nil? ? 'nil' : subject.to_s}"}
266
268
 
267
269
  unless el.uri.to_s == RDF.Description.to_s
268
270
  add_triple(el, subject, RDF.type, el.uri)
@@ -270,7 +272,7 @@ module RDF::RDFXML
270
272
 
271
273
  # produce triples for attributes
272
274
  el.attribute_nodes.each do |attr|
273
- add_debug(el, "propertyAttr: #{attr.uri}='#{attr.value}'")
275
+ add_debug(el) {"propertyAttr: #{attr.uri}='#{attr.value}'"}
274
276
  if attr.uri.to_s == RDF.type.to_s
275
277
  # If there is an attribute a in propertyAttr with a.URI == rdf:type
276
278
  # then u:=uri(identifier:=resolve(a.string-value))
@@ -293,16 +295,16 @@ module RDF::RDFXML
293
295
  prefix(prefix, value)
294
296
  end
295
297
  predicate = child.uri
296
- add_debug(child, "propertyElt, predicate: #{predicate}")
298
+ add_debug(child) {"propertyElt, predicate: #{predicate}"}
297
299
  propertyElementURI_check(child)
298
300
 
299
301
  # Determine the content type of this property element
300
302
  text_nodes = child.children.select {|e| e.text? && !e.blank?}
301
303
  element_nodes = child.children.select {|c| c.element? }
302
- add_debug(child, "#{text_nodes.length} text nodes, #{element_nodes.length} element nodes")
304
+ add_debug(child) {"#{text_nodes.length} text nodes, #{element_nodes.length} element nodes"}
303
305
  if element_nodes.length > 1
304
306
  element_nodes.each do |node|
305
- add_debug(child, " node: #{node.to_s}")
307
+ add_debug(child) {" node: #{node.to_s}"}
306
308
  end
307
309
  end
308
310
 
@@ -326,7 +328,7 @@ module RDF::RDFXML
326
328
  # RDF/XML documents specified in [RDF-MS] to remain valid;
327
329
  # new documents SHOULD NOT use these unqualified attributes and applications
328
330
  # MAY choose to warn when the unqualified form is seen in a document.
329
- add_debug(el, "Unqualified attribute '#{attr}'")
331
+ add_debug(el) {"Unqualified attribute '#{attr}'"}
330
332
  #attrs[attr.to_s] = attr.value unless attr.to_s.match?(/^xml/)
331
333
  elsif attr.namespace.href == RDF::XML.to_s
332
334
  # No production. Lang and base elements already extracted
@@ -354,12 +356,12 @@ module RDF::RDFXML
354
356
  resourceAttr = RDF::NTriples.unescape(resourceAttr) if resourceAttr
355
357
  nodeID = nodeID_check(el, RDF::NTriples.unescape(nodeID)) if nodeID
356
358
 
357
- add_debug(child, "attrs: #{attrs.inspect}")
358
- add_debug(child, "datatype: #{datatype}") if datatype
359
- add_debug(child, "parseType: #{parseType}") if parseType
360
- add_debug(child, "resource: #{resourceAttr}") if resourceAttr
361
- add_debug(child, "nodeID: #{nodeID}") if nodeID
362
- add_debug(child, "id: #{id}") if id
359
+ add_debug(child) {"attrs: #{attrs.inspect}"}
360
+ add_debug(child) {"datatype: #{datatype}"} if datatype
361
+ add_debug(child) {"parseType: #{parseType}"} if parseType
362
+ add_debug(child) {"resource: #{resourceAttr}"} if resourceAttr
363
+ add_debug(child) {"nodeID: #{nodeID}"} if nodeID
364
+ add_debug(child) {"id: #{id}"} if id
363
365
 
364
366
  if attrs.empty? && datatype.nil? && parseType.nil? && element_nodes.length == 1
365
367
  # Production resourcePropertyElt
@@ -368,7 +370,7 @@ module RDF::RDFXML
368
370
  prefix(prefix, value)
369
371
  end
370
372
  new_node_element = element_nodes.first
371
- add_debug(child, "resourcePropertyElt: #{node_path(new_node_element)}")
373
+ add_debug(child) {"resourcePropertyElt: #{node_path(new_node_element)}"}
372
374
  new_subject = nodeElement(new_node_element, new_ec)
373
375
  add_triple(child, subject, predicate, new_subject)
374
376
  elsif attrs.empty? && parseType.nil? && element_nodes.length == 0 && text_nodes.length > 0
@@ -487,7 +489,7 @@ module RDF::RDFXML
487
489
 
488
490
  # produce triples for attributes
489
491
  attrs.each_pair do |attr, val|
490
- add_debug(el, "attr: #{attr.name}='#{val}'")
492
+ add_debug(el) {"attr: #{attr.name}='#{val}'"}
491
493
 
492
494
  if attr.uri.to_s == RDF.type.to_s
493
495
  add_triple(child, resource, RDF.type, val)
@@ -542,16 +544,16 @@ module RDF::RDFXML
542
544
 
543
545
  case
544
546
  when id
545
- add_debug(el, "parse_subject, id: '#{RDF::NTriples.unescape(id.value)}'")
547
+ add_debug(el) {"parse_subject, id: #{RDF::NTriples.unescape(id.value).inspect}"}
546
548
  id_check(el, RDF::NTriples.unescape(id.value), ec.base) # Returns URI
547
549
  when nodeID
548
550
  # The value of rdf:nodeID must match the XML Name production
549
551
  nodeID = nodeID_check(el, RDF::NTriples.unescape(nodeID.value))
550
- add_debug(el, "parse_subject, nodeID: '#{nodeID}")
552
+ add_debug(el) {"parse_subject, nodeID: #{nodeID.inspect}"}
551
553
  bnode(nodeID)
552
554
  when about
553
555
  about = RDF::NTriples.unescape(about.value)
554
- add_debug(el, "parse_subject, about: '#{about}'")
556
+ add_debug(el) {"parse_subject, about: #{about.inspect}"}
555
557
  ec.base.join(about)
556
558
  else
557
559
  add_debug(el, "parse_subject, BNode")
@@ -627,7 +629,7 @@ module RDF::RDFXML
627
629
  def old_property_check(el)
628
630
  el.attribute_nodes.each do |attr|
629
631
  if OLD_TERMS.include?(attr.uri.to_s)
630
- add_debug(el, "Obsolete attribute '#{attr.uri}'")
632
+ add_debug(el) {"Obsolete attribute '#{attr.uri}'"}
631
633
  raise RDF::ReaderError.new("Obsolete attribute '#{attr.uri}'") if validate?
632
634
  end
633
635
  end
@@ -138,23 +138,23 @@ module RDF::RDFXML
138
138
 
139
139
  doc = Nokogiri::XML::Document.new
140
140
 
141
- add_debug "\nserialize: graph of size #{@graph.size}"
142
- add_debug "options: #{@options.inspect}"
141
+ add_debug {"\nserialize: graph of size #{@graph.size}"}
142
+ add_debug {"options: #{@options.inspect}"}
143
143
 
144
144
  preprocess
145
145
 
146
146
  prefix(:rdf, RDF.to_uri)
147
- prefix(:xml, RDF::XML) if @base_uri || @lang
147
+ prefix(:xml, RDF::XML) if base_uri || @lang
148
148
 
149
- add_debug "\nserialize: graph namespaces: #{prefixes.inspect}"
149
+ add_debug {"\nserialize: graph namespaces: #{prefixes.inspect}"}
150
150
 
151
151
  doc.root = Nokogiri::XML::Element.new("rdf:RDF", doc)
152
152
  doc.root["xml:lang"] = @lang if @lang
153
- doc.root["xml:base"] = @base_uri if @base_uri
153
+ doc.root["xml:base"] = base_uri if base_uri
154
154
 
155
155
  # Add statements for each subject
156
156
  order_subjects.each do |subject|
157
- #add_debug "subj: #{subject.inspect}"
157
+ #add_debug "{subj: #{subject.inspect}"}
158
158
  subject(subject, doc.root)
159
159
  end
160
160
 
@@ -166,7 +166,7 @@ module RDF::RDFXML
166
166
  end
167
167
  end
168
168
 
169
- add_debug "doc:\n #{doc.to_xml(:encoding => "UTF-8", :indent => 2)}"
169
+ add_debug {"doc:\n #{doc.to_xml(:encoding => "UTF-8", :indent => 2)}"}
170
170
  doc.write_xml_to(@output, :encoding => "UTF-8", :indent => 2)
171
171
  end
172
172
 
@@ -178,22 +178,22 @@ module RDF::RDFXML
178
178
  def get_qname(resource, options = {})
179
179
  case resource
180
180
  when RDF::Node
181
- add_debug "qname(#{resource.inspect}): #{resource}"
181
+ add_debug {"qname(#{resource.inspect}): #{resource}"}
182
182
  return resource.to_s
183
183
  when RDF::URI
184
184
  uri = resource.to_s
185
185
  else
186
- add_debug "qname(#{resource.inspect}): nil"
186
+ add_debug {"qname(#{resource.inspect}): nil"}
187
187
  return nil
188
188
  end
189
189
 
190
190
  qname = case
191
191
  when options[:with_default] && prefix(nil) && uri.index(prefix(nil)) == 0
192
192
  # Don't cache
193
- add_debug "qname(#{resource.inspect}): #{uri.sub(prefix(nil), '').inspect} (default)"
193
+ add_debug {"qname(#{resource.inspect}): #{uri.sub(prefix(nil), '').inspect} (default)"}
194
194
  return uri.sub(prefix(nil), '')
195
195
  when @uri_to_qname.has_key?(uri)
196
- add_debug "qname(#{resource.inspect}): #{@uri_to_qname[uri].inspect} (cached)"
196
+ add_debug {"qname(#{resource.inspect}): #{@uri_to_qname[uri].inspect} (cached)"}
197
197
  return @uri_to_qname[uri]
198
198
  when u = @uri_to_prefix.keys.detect {|u| uri.index(u.to_s) == 0 && NC_REGEXP.match(uri[u.to_s.length..-1])}
199
199
  # Use a defined prefix
@@ -225,19 +225,19 @@ module RDF::RDFXML
225
225
  "#{@gen_prefix}:#{suffix}"
226
226
  end
227
227
 
228
- add_debug "qname(#{resource.inspect}): #{qname.inspect}"
228
+ add_debug {"qname(#{resource.inspect}): #{qname.inspect}"}
229
229
  @uri_to_qname[uri] = qname
230
230
  rescue Addressable::URI::InvalidURIError => e
231
231
  raise RDF::WriterError, "Invalid URI #{uri.inspect}: #{e.message}"
232
232
  end
233
233
 
234
234
  protected
235
- # If @base_uri is defined, use it to try to make uri relative
235
+ # If base_uri is defined, use it to try to make uri relative
236
236
  # @param [#to_s] uri
237
237
  # @return [String]
238
238
  def relativize(uri)
239
239
  uri = uri.to_s
240
- @base_uri ? uri.sub(@base_uri.to_s, "") : uri
240
+ base_uri ? uri.sub(base_uri.to_s, "") : uri
241
241
  end
242
242
 
243
243
  # Defines rdf:type of subjects to be emitted at the beginning of the graph. Defaults to none
@@ -259,7 +259,7 @@ module RDF::RDFXML
259
259
 
260
260
  top_classes.each do |class_uri|
261
261
  graph.query(:predicate => RDF.type, :object => class_uri).map {|st| st.subject}.sort.uniq.each do |subject|
262
- #add_debug "order_subjects: #{subject.inspect}"
262
+ #add_debug "{order_subjects: #{subject.inspect}"}
263
263
  subjects << subject
264
264
  seen[subject] = @top_levels[subject] = true
265
265
  end
@@ -285,7 +285,7 @@ module RDF::RDFXML
285
285
  @options[:prefixes] = {} # Will define actual used when matched
286
286
 
287
287
  if default_namespace
288
- add_debug("preprocess: default_namespace: #{default_namespace}")
288
+ add_debug {"preprocess: default_namespace: #{default_namespace}"}
289
289
  prefix(nil, default_namespace)
290
290
  end
291
291
 
@@ -296,7 +296,7 @@ module RDF::RDFXML
296
296
  # prefixes.
297
297
  # @param [Statement] statement
298
298
  def preprocess_statement(statement)
299
- #add_debug "preprocess: #{statement.inspect}"
299
+ #add_debug {"preprocess: #{statement.inspect}"}
300
300
  references = ref_count(statement.object) + 1
301
301
  @references[statement.object] = references
302
302
  @subjects[statement.subject] = true
@@ -328,7 +328,7 @@ module RDF::RDFXML
328
328
  if !is_done?(subject)
329
329
  subject_done(subject)
330
330
  properties = @graph.properties(subject)
331
- add_debug "subject: #{subject.inspect}, props: #{properties.inspect}"
331
+ add_debug {"subject: #{subject.inspect}, props: #{properties.inspect}"}
332
332
 
333
333
  @graph.query(:subject => subject).each do |st|
334
334
  raise RDF::WriterError, "Illegal use of predicate #{st.predicate.inspect}, not supported in RDF/XML" unless st.predicate.uri?
@@ -345,7 +345,7 @@ module RDF::RDFXML
345
345
  properties[RDF.type.to_s] = [rest].flatten.compact
346
346
  end
347
347
  prop_list = order_properties(properties)
348
- add_debug "=> property order: #{prop_list.to_sentence}"
348
+ add_debug {"=> property order: #{prop_list.to_sentence}"}
349
349
 
350
350
  if qname
351
351
  rdf_type = nil
@@ -381,7 +381,7 @@ module RDF::RDFXML
381
381
  end
382
382
  end
383
383
  elsif @force_RDF_about.include?(subject)
384
- add_debug "subject: #{subject.inspect}, force about"
384
+ add_debug {"subject: #{subject.inspect}, force about"}
385
385
  node = Nokogiri::XML::Element.new("rdf:Description", parent_node.document)
386
386
  if subject.is_a?(RDF::Node)
387
387
  node["rdf:nodeID"] = subject.id
@@ -403,7 +403,13 @@ module RDF::RDFXML
403
403
  qname = get_qname(prop, :with_default => !as_attr)
404
404
  raise RDF::WriterError, "No qname generated for <#{prop}>" unless qname
405
405
 
406
- add_debug "predicate: #{qname}, as_attr: #{as_attr}, object: #{object.inspect}, done: #{is_done?(object)}, subject: #{@subjects.include?(object)}"
406
+ add_debug do
407
+ "predicate: #{qname}, " +
408
+ "as_attr: #{as_attr}, " +
409
+ "object: #{object.inspect}, " +
410
+ "done: #{is_done?(object)}, " +
411
+ "subject: #{@subjects.include?(object)}"
412
+ end
407
413
  #qname = "rdf:li" if qname.match(/rdf:_\d+/)
408
414
  pred_node = Nokogiri::XML::Element.new(qname, node.document)
409
415
 
@@ -416,7 +422,7 @@ module RDF::RDFXML
416
422
 
417
423
  # Check to see if it can be serialized as a collection
418
424
  if conformant_list
419
- add_debug("=> as collection: [#{col.map(&:to_s).join(", ")}]")
425
+ add_debug {"=> as collection: [#{col.map(&:to_s).join(", ")}]"}
420
426
  # Serialize list as parseType="Collection"
421
427
  pred_node.add_child(Nokogiri::XML::Comment.new(node.document, "Serialization for #{object}")) if RDF::RDFXML::debug?
422
428
  pred_node["rdf:parseType"] = "Collection"
@@ -426,7 +432,7 @@ module RDF::RDFXML
426
432
  item = o_props[RDF.first.to_s].first
427
433
  object = o_props[RDF.rest.to_s].first
428
434
  o_props = @graph.properties(object)
429
- add_debug("=> li first: #{item}, rest: #{object}")
435
+ add_debug {"=> li first: #{item}, rest: #{object}"}
430
436
  @force_RDF_about[item] = true
431
437
  subject(item, pred_node)
432
438
  end
@@ -435,16 +441,16 @@ module RDF::RDFXML
435
441
  pred_node.unlink
436
442
  pred_node = nil
437
443
  node[qname] = object.is_a?(RDF::URI) ? relativize(object) : object.value
438
- add_debug("=> as attribute: node[#{qname}]=#{node[qname]}, #{object.class}")
444
+ add_debug {"=> as attribute: node[#{qname}]=#{node[qname]}, #{object.class}"}
439
445
  elsif object.literal?
440
446
  # Serialize as element
441
- add_debug("predicate as element: #{attrs.inspect}")
447
+ add_debug {"predicate as element: #{attrs.inspect}"}
442
448
  attrs.each_pair do |a, av|
443
449
  next if a.to_s == "xml:lang" && av.to_s == @lang # Lang already specified, don't repeat
444
- add_debug "=> elt attr #{a}=#{av}"
450
+ add_debug {"=> elt attr #{a}=#{av}"}
445
451
  pred_node[a] = av.to_s
446
452
  end
447
- add_debug "=> elt #{'xmllit ' if object.literal? && object.datatype == RDF.XMLLiteral}content=#{args.first}" if !args.empty?
453
+ add_debug {"=> elt #{'xmllit ' if object.literal? && object.datatype == RDF.XMLLiteral}content=#{args.first}"} if !args.empty?
448
454
  if object.datatype == RDF.XMLLiteral
449
455
  pred_node.inner_html = args.first.to_s
450
456
  elsif args.first
@@ -468,7 +474,7 @@ module RDF::RDFXML
468
474
 
469
475
  # Mark a subject as done.
470
476
  def subject_done(subject)
471
- add_debug("subject_done: #{subject}")
477
+ add_debug {"subject_done: #{subject}"}
472
478
  @serialized[subject] = true
473
479
  end
474
480
 
@@ -478,7 +484,7 @@ module RDF::RDFXML
478
484
  end
479
485
 
480
486
  def is_done?(subject)
481
- #add_debug("is_done?(#{subject}): #{@serialized.include?(subject)}")
487
+ #add_debug {"is_done?(#{subject}): #{@serialized.include?(subject)}"}
482
488
  @serialized.include?(subject)
483
489
  end
484
490
 
@@ -544,9 +550,12 @@ module RDF::RDFXML
544
550
 
545
551
  # Add debug event to debug array, if specified
546
552
  #
547
- # @param [String] message::
548
- def add_debug(message)
549
- msg = "#{indent}#{message}"
553
+ # @param [String] message
554
+ # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
555
+ def add_debug(message = "")
556
+ return unless ::RDF::RDFXML.debug? || @debug
557
+ message = message + yield if block_given?
558
+ msg = "#{' ' * @depth}#{message}"
550
559
  STDERR.puts msg if ::RDF::RDFXML.debug?
551
560
  @debug << msg if @debug.is_a?(Array)
552
561
  end