Class: Metacrunch::Mab2::XmlBuilder
- Inherits:
-
Object
- Object
- Metacrunch::Mab2::XmlBuilder
- Defined in:
- lib/metacrunch/mab2/xml_builder.rb
Instance Method Summary collapse
-
#initialize(identifier = nil, &block) ⇒ XmlBuilder
constructor
A new instance of XmlBuilder.
- #to_xml ⇒ Object
Constructor Details
#initialize(identifier = nil, &block) ⇒ XmlBuilder
Returns a new instance of XmlBuilder.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/metacrunch/mab2/xml_builder.rb', line 5 def initialize(identifier = nil, &block) @builder = Nokogiri::XML::Builder.new do send( :"OAI-PMH", "xmlns" => "http://www.openarchives.org/OAI/2.0/", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd" ) do ListRecords do record do if identifier header do |_xml| _xml.identifier identifier end end do record("xmlns" => "http://www.ddb.de/professionell/mabxml/mabxml-1.xsd") do define_singleton_method(:controlfield) do |_tag, _text| send(:method_missing, :controlfield, _text, tag: _tag) end define_singleton_method(:datafield) do |_tag, _attributes = {}, &_block| send(:method_missing, :datafield, {tag: _tag}.merge(_attributes), &_block) end define_singleton_method(:subfield) do |_code, _text| send(:method_missing, :subfield, _text, code: _code) end instance_eval(&block) end end end end end end end |
Instance Method Details
#to_xml ⇒ Object
45 46 47 |
# File 'lib/metacrunch/mab2/xml_builder.rb', line 45 def to_xml @builder.to_xml end |