Class: Amanzi::XML::Document
Instance Attribute Summary
Attributes inherited from Element
#attributes, #children, #depth, #name, #namespace
Instance Method Summary
collapse
Methods inherited from Element
#<<, #[]=, #add_child, #attribute_text, camelize, #contents, #indent, #initialize, #insert, #insert_child, #make_child, #ns, #tag
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
111
112
113
114
|
# File 'lib/amanzi/xml.rb', line 111
def method_missing(symbol,*args,&block)
singleton_method(symbol,*args,&block) || super(symbol,*args,&block)
end
|
Instance Method Details
#add_singleton_elements(elements = []) ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/amanzi/xml.rb', line 90
def add_singleton_elements(elements=[])
prev_e = nil
singleton_elements << elements.map do |e|
parent = prev_e || self
element = Element.new(Element.camelize(e), parent.depth + 1)
parent << element
prev_e = element
end
end
|
87
88
89
|
# File 'lib/amanzi/xml.rb', line 87
def text
!@singleton_elements.empty? && @singleton_elements.flatten[-1].(text)
end
|
#singleton_elements ⇒ Object
84
85
86
|
# File 'lib/amanzi/xml.rb', line 84
def singleton_elements
@singleton_elements ||= []
end
|
#singleton_method(symbol, *args, &block) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/amanzi/xml.rb', line 99
def singleton_method(symbol,*args,&block)
name = Element.camelize symbol
singleton_elements.flatten.each do |element|
if element.name === name
block && block.call(element)
return element
end
end
nil
end
|
#to_s ⇒ Object
115
116
117
|
# File 'lib/amanzi/xml.rb', line 115
def to_s
to_xml
end
|
#to_xml(options = {}) ⇒ Object
81
82
83
|
# File 'lib/amanzi/xml.rb', line 81
def to_xml(options={})
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" + super(options) + "\n"
end
|