Class: EAAL::Result::ResultElement
- Inherits:
-
Object
- Object
- EAAL::Result::ResultElement
- Defined in:
- lib/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.
49 50 51 52 53 |
# File 'lib/eaal/result.rb', line 49 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
59 60 61 62 63 64 65 |
# File 'lib/eaal/result.rb', line 59 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.
48 49 50 |
# File 'lib/eaal/result.rb', line 48 def attribs @attribs end |
#name ⇒ Object
Returns the value of attribute name.
48 49 50 |
# File 'lib/eaal/result.rb', line 48 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
48 49 50 |
# File 'lib/eaal/result.rb', line 48 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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/eaal/result.rb', line 69 def self.parse_element(prefix, element) if element.name == "rowset" then 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 celement.attributes.to_hash.length > 0 container.add_element(cel.name, cel) else container.add_element(cel.name, cel.value) end } value = container else # Mainly to filter HTML tags within description element in corporationsheet. value = element.inner_html.gsub(/(<|<)(.|\n)*?(>|>)/, "") end re = ResultElement.new(key, value) if element.attributes.to_hash.length > 0 re.attribs.merge!(element.attributes.to_hash) if re.value.respond_to?(:attribs) re.value.attribs.merge!(element.attributes.to_hash) end end end re end |
Instance Method Details
#add_attrib(key, val) ⇒ Object
55 56 57 |
# File 'lib/eaal/result.rb', line 55 def add_attrib(key, val) self.attribs.merge!({key => val}) end |