Class: Extreml::XmlHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/extreml/xml_header.rb

Overview

Exposes the xml header properties as methods

Instance Method Summary collapse

Constructor Details

#initialize(header) ⇒ XmlHeader

Initialize

Parameters:

  • header (Hash|String)

    the header.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/extreml/xml_header.rb', line 30

def initialize header

  h = header.scan /([\w\?\<]*)=["|']([^'"]*)["|']/
  if h.empty?
    @attributes = nil
  else
    @attributes = Array.new
    h.each do |param|
      @attributes << param[0].to_sym
      define_singleton_method param[0].to_sym do
        return param[1]
      end
    end
  end
end

Instance Method Details

#to_xmlObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/extreml/xml_header.rb', line 46

def to_xml
  if @attributes.nil?
    header = ''
  else
    header = '<?xml'
    @attributes.each do |a|
      header += " #{a.to_s}=\"#{self.send(a)}\""
    end
    header += '?>'
  end

  return header
end