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 = nil) ⇒ XmlHeader

Initialize

Parameters:

  • (defaults to: nil)

    the header.



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

def initialize header = nil
  if header.nil?
    h = [
      ["version",1.0],
      ["encoding","UTF-8"]
    ]
  else
    h = header.scan /([\w\?\<]*)=["|']([^'"]*)["|']/
  end
  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



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/extreml/xml_header.rb', line 52

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