class Extreml::XmlHeader

Exposes the xml header properties as methods

Public Class Methods

new(header = nil) click to toggle source

Initialize

@param header [Hash|String] the header. @return [XmlHeader] the object.

# 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

Public Instance Methods

to_xml() click to toggle source
# 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