Class: XmlHate::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/xml_hate/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Document

Returns a new instance of Document.



6
7
8
# File 'lib/xml_hate/document.rb', line 6

def initialize(xml)
  @document = lower_case_please(XmlSimple.xml_in(xml))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/xml_hate/document.rb', line 10

def method_missing(meth, *args, &blk)
  meth = meth.to_s
  unless @document.has_key?(meth)
    if @document.has_key?(meth.singularize)
      meth = meth.singularize
    else
      return ''
    end
  end
  objects = pull_the_objects_from_the_xml_document(meth)
  objects.count == 1 ? objects[0] : objects
end