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
:nodoc:.
-
#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.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rdf/rdfxml/reader.rb', line 25 def initialize(base, element, graph, &cb) # Initialize the evaluation context, [5.1] self.base = RDF::URI.intern(base) @uri_mappings = {} @language = nil @graph = graph @li_counter = 0 extract_from_element(element, &cb) if element end |
Instance Attribute Details
#base ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/rdf/rdfxml/reader.rb', line 18 def base @base end |
#graph ⇒ Object
Returns the value of attribute graph.
22 23 24 |
# File 'lib/rdf/rdfxml/reader.rb', line 22 def graph @graph end |
#language ⇒ Object
Returns the value of attribute language.
21 22 23 |
# File 'lib/rdf/rdfxml/reader.rb', line 21 def language @language end |
#li_counter ⇒ Object
Returns the value of attribute li_counter.
23 24 25 |
# File 'lib/rdf/rdfxml/reader.rb', line 23 def li_counter @li_counter end |
#subject ⇒ Object
Returns the value of attribute subject.
19 20 21 |
# File 'lib/rdf/rdfxml/reader.rb', line 19 def subject @subject end |
#uri_mappings ⇒ Object
Returns the value of attribute uri_mappings.
20 21 22 |
# File 'lib/rdf/rdfxml/reader.rb', line 20 def uri_mappings @uri_mappings end |
Instance Method Details
#clone(element, options = {}, &cb) ⇒ Object
Clone existing evaluation context adding information from element
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rdf/rdfxml/reader.rb', line 37 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
49 50 51 52 53 54 55 56 57 |
# File 'lib/rdf/rdfxml/reader.rb', line 49 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
60 61 62 63 64 65 66 |
# File 'lib/rdf/rdfxml/reader.rb', line 60 def extract_from_element(el, &cb) b = el.attribute_with_ns("base", RDF::XML.to_s) lang = el.attribute_with_ns("lang", RDF::XML.to_s) self.base = self.base.join(b) if b self.language = lang if lang self.uri_mappings.merge!(extract_mappings(el, &cb)) end |
#extract_mappings(element, &cb) ⇒ Object
Extract the XMLNS mappings from an element
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rdf/rdfxml/reader.rb', line 69 def extract_mappings(element, &cb) mappings = {} # look for xmlns element.namespaces.each do |attr_name,attr_value| abbr, prefix = attr_name.to_s.split(":") if abbr == "xmlns" attr_value = self.base.to_s + attr_value if attr_value.match(/^\#/) mappings[prefix] = attr_value cb.call(prefix, attr_value) if block_given? end end mappings end |
#inspect ⇒ Object
97 98 99 100 101 |
# File 'lib/rdf/rdfxml/reader.rb', line 97 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
85 86 87 88 |
# File 'lib/rdf/rdfxml/reader.rb', line 85 def li_next @li_counter += 1 predicate = RDF["_#{@li_counter}"] end |