Class: TaliaCore::ActiveSourceParts::Xml::SourceBuilder

Inherits:
TaliaUtil::Xml::BaseBuilder show all
Defined in:
lib/talia_core/active_source_parts/xml/source_builder.rb

Overview

Class to build source representations of ActiveSource objects. Talia uses a simple XML format to encode the Source Object. The format maps easily to a Hash as it is used for the new or write_attributes methods:

<sources>
  <source>
    <attribute>
      <predicate>http://foobar/</predicate>
      <object>http://barbar/</object>
    </attribute>
    ...
  </source>
  <source>
    <attribute>
      <predicate>http://foobar/bar/</pedicate>
      <value>val</value>
      <object>http://some_url</object>
      <value>another</value>
      ...
    </attribute>
    ...
  </source>
  ...
</sources>

Also see the parent class, TaliaUtil::Xml::BaseBuilder, for more information

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TaliaUtil::Xml::BaseBuilder

make_xml_string, open

Class Method Details

.build_source(source) ⇒ Object

Builds the XML for a single source, and returns the result as a string



36
37
38
# File 'lib/talia_core/active_source_parts/xml/source_builder.rb', line 36

def self.build_source(source)
  make_xml_string { |build| build.write_source(source) }
end

Instance Method Details

#write_source(source) ⇒ Object

Build the XML for a single source.



41
42
43
44
45
46
# File 'lib/talia_core/active_source_parts/xml/source_builder.rb', line 41

def write_source(source)
  @builder.source do 
    source.attributes.each { |attrib, value| write_attribute(attrib, value) }
    source.direct_predicates.each { |pred| write_attribute(pred, source[pred]) } 
  end
end