Class: RDF::RDFXML::Reader::EvaluationContext
- Inherits:
-
Object
- Object
- RDF::RDFXML::Reader::EvaluationContext
- Defined in:
- lib/rdf/rdfxml/reader.rb
Overview
The Recursive Baggage
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#graph ⇒ Object
Returns the value of attribute graph.
-
#language ⇒ Object
Returns the value of attribute language.
-
#li_counter ⇒ Object
Returns the value of attribute li_counter.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#uri_mappings ⇒ Object
Returns the value of attribute uri_mappings.
Instance Method Summary collapse
-
#clone(element, options = {}, &cb) ⇒ Object
Clone existing evaluation context adding information from element.
-
#extract_from_ancestors(el, &cb) ⇒ Object
Extract Evaluation Context from an element by looking at ancestors recurively.
-
#extract_from_element(el, &cb) ⇒ Object
Extract Evaluation Context from an element.
-
#extract_mappings(element, &cb) ⇒ Object
Extract the XMLNS mappings from an element.
-
#initialize(base, element, graph, &cb) ⇒ EvaluationContext
constructor
A new instance of EvaluationContext.
- #inspect ⇒ Object
-
#li_next ⇒ Object
Produce the next list entry for this context.
Constructor Details
#initialize(base, element, graph, &cb) ⇒ EvaluationContext
Returns a new instance of EvaluationContext.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rdf/rdfxml/reader.rb', line 32 def initialize(base, element, graph, &cb) # Initialize the evaluation context, [5.1] self.base = RDF::URI(base) @uri_mappings = {} @language = nil @graph = graph @li_counter = 0 extract_from_element(element, &cb) if element end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
25 26 27 |
# File 'lib/rdf/rdfxml/reader.rb', line 25 def base @base end |
#graph ⇒ Object
Returns the value of attribute graph.
29 30 31 |
# File 'lib/rdf/rdfxml/reader.rb', line 29 def graph @graph end |
#language ⇒ Object
Returns the value of attribute language.
28 29 30 |
# File 'lib/rdf/rdfxml/reader.rb', line 28 def language @language end |
#li_counter ⇒ Object
Returns the value of attribute li_counter.
30 31 32 |
# File 'lib/rdf/rdfxml/reader.rb', line 30 def li_counter @li_counter end |
#subject ⇒ Object
Returns the value of attribute subject.
26 27 28 |
# File 'lib/rdf/rdfxml/reader.rb', line 26 def subject @subject end |
#uri_mappings ⇒ Object
Returns the value of attribute uri_mappings.
27 28 29 |
# File 'lib/rdf/rdfxml/reader.rb', line 27 def uri_mappings @uri_mappings end |
Instance Method Details
#clone(element, options = {}, &cb) ⇒ Object
Clone existing evaluation context adding information from element
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rdf/rdfxml/reader.rb', line 44 def clone(element, = {}, &cb) new_ec = EvaluationContext.new(@base, nil, @graph) new_ec.uri_mappings = self.uri_mappings.clone new_ec.language = self.language new_ec.extract_from_element(element, &cb) if element .each_pair {|k, v| new_ec.send("#{k}=", v)} new_ec end |
#extract_from_ancestors(el, &cb) ⇒ Object
Extract Evaluation Context from an element by looking at ancestors recurively
56 57 58 59 60 61 62 63 64 |
# File 'lib/rdf/rdfxml/reader.rb', line 56 def extract_from_ancestors(el, &cb) ancestors = el.ancestors while ancestors.length > 0 a = ancestors.pop next unless a.element? extract_from_element(a, &cb) end extract_from_element(el, &cb) end |
#extract_from_element(el, &cb) ⇒ Object
Extract Evaluation Context from an element
67 68 69 70 71 72 73 74 |
# File 'lib/rdf/rdfxml/reader.rb', line 67 def extract_from_element(el, &cb) self.language = el.language if el.language if b = el.base b = RDF::URI(b) self.base = b.absolute? ? b : self.base.join(b) end self.uri_mappings.merge!(extract_mappings(el, &cb)) end |
#extract_mappings(element, &cb) ⇒ Object
Extract the XMLNS mappings from an element
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rdf/rdfxml/reader.rb', line 77 def extract_mappings(element, &cb) mappings = {} # look for xmlns element.namespaces.each do |prefix, value| value = base.join(value) mappings[prefix] = value cb.call(prefix, value) if block_given? end mappings end |
#inspect ⇒ Object
100 101 102 103 104 |
# File 'lib/rdf/rdfxml/reader.rb', line 100 def inspect v = %w(base subject language).map {|a| "#{a}='#{self.send(a).nil? ? 'nil' : self.send(a)}'"} v << "uri_mappings[#{uri_mappings.keys.length}]" v.join(",") end |
#li_next ⇒ Object
Produce the next list entry for this context
90 91 92 93 |
# File 'lib/rdf/rdfxml/reader.rb', line 90 def li_next @li_counter += 1 predicate = RDF["_#{@li_counter}"] end |