Class: EAAL::Result::ResultElement
- Inherits:
-
Object
- Object
- EAAL::Result::ResultElement
- Defined in:
- lib/eaal/eaal_result.rb
Overview
result element
Instance Attribute Summary collapse
-
#attribs ⇒ Object
Returns the value of attribute attribs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.parse_element(prefix, element) ⇒ Object
parses an xml element to create either the ResultElement, ResultContainer or Rowset necessary.
Instance Method Summary collapse
- #add_attrib(key, val) ⇒ Object
-
#initialize(name, value) ⇒ ResultElement
constructor
A new instance of ResultElement.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(name, value) ⇒ ResultElement
Returns a new instance of ResultElement.
35 36 37 38 39 |
# File 'lib/eaal/eaal_result.rb', line 35 def initialize(name, value) self.name = name self.value = value self.attribs = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/eaal/eaal_result.rb', line 45 def method_missing(method, *args) if self.attribs.has_key?(method.id2name) self.attribs[method.id2name] else self.value.send(method, *args) end end |
Instance Attribute Details
#attribs ⇒ Object
Returns the value of attribute attribs.
34 35 36 |
# File 'lib/eaal/eaal_result.rb', line 34 def attribs @attribs end |
#name ⇒ Object
Returns the value of attribute name.
34 35 36 |
# File 'lib/eaal/eaal_result.rb', line 34 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
34 35 36 |
# File 'lib/eaal/eaal_result.rb', line 34 def value @value end |
Class Method Details
.parse_element(prefix, element) ⇒ Object
parses an xml element to create either the ResultElement, ResultContainer or Rowset necessary
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/eaal/eaal_result.rb', line 56 def self.parse_element(prefix, element) if element.name == "rowset" re = EAAL::Rowset.new(prefix, element) else key = element.name if element.children && element.containers.length > 0 container = ResultContainer.new element.containers.each { |celement| cel = EAAL::Result::ResultElement.parse_element(prefix, celement) if element.attributes.length > 0 container.add_element(cel.name, cel) else container.add_element(cel.name, cel.value) end } value = container else value = element.inner_html end re = ResultElement.new(key, value) if element.attributes.length > 0 re.attribs.merge!(element.attributes) end end re end |
Instance Method Details
#add_attrib(key, val) ⇒ Object
41 42 43 |
# File 'lib/eaal/eaal_result.rb', line 41 def add_attrib(key, val) self.attribs.merge!({key => val}) end |