Class: IqRdf::Collection
- Inherits:
-
Object
- Object
- IqRdf::Collection
- Defined in:
- lib/iq_rdf/collection.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #build_xml(xml, elements = nil, &block) ⇒ Object
-
#initialize(collection) ⇒ Collection
constructor
A new instance of Collection.
- #to_s(options = {}) ⇒ Object
Constructor Details
#initialize(collection) ⇒ Collection
Returns a new instance of Collection.
20 21 22 23 24 25 26 |
# File 'lib/iq_rdf/collection.rb', line 20 def initialize(collection) @elements = [] collection.each do |element| element = Literal.new(element) unless element.is_a?(IqRdf::Uri) || element.is_a?(IqRdf::Literal) @elements << element end end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
18 19 20 |
# File 'lib/iq_rdf/collection.rb', line 18 def elements @elements end |
Instance Method Details
#build_xml(xml, elements = nil, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/iq_rdf/collection.rb', line 32 def build_xml(xml, elements = nil, &block) elements ||= @elements.dup block.call({}, lambda { xml.rdf :List do elements.shift.build_xml(xml) do |*args| xml.rdf(:first, *args) end if elements.size > 0 build_xml(xml, elements) do |opts, block| xml.rdf :rest do block.call end end else xml.rdf :rest, "rdf:resource" => Rdf.nil.full_uri end end } ) end |
#to_s(options = {}) ⇒ Object
28 29 30 |
# File 'lib/iq_rdf/collection.rb', line 28 def to_s( = {}) "(#{@elements.map{|e| e.to_s()}.join(" ")})" end |