Class: LazyXmlModel::ElementProxy
- Inherits:
-
Object
- Object
- LazyXmlModel::ElementProxy
- Defined in:
- lib/lazy_xml_model/element_proxy.rb
Instance Attribute Summary collapse
-
#element_tag ⇒ Object
readonly
Returns the value of attribute element_tag.
-
#xml_document ⇒ Object
readonly
Returns the value of attribute xml_document.
-
#xml_parent_element ⇒ Object
readonly
Returns the value of attribute xml_parent_element.
Instance Method Summary collapse
-
#initialize(element_tag, xml_document, xml_parent_element) ⇒ ElementProxy
constructor
A new instance of ElementProxy.
-
#value ⇒ Object
Getter Method.
-
#value=(value) ⇒ Object
Setter Method.
Constructor Details
#initialize(element_tag, xml_document, xml_parent_element) ⇒ ElementProxy
Returns a new instance of ElementProxy.
5 6 7 8 9 |
# File 'lib/lazy_xml_model/element_proxy.rb', line 5 def initialize(element_tag, xml_document, xml_parent_element) @element_tag = element_tag @xml_document = xml_document @xml_parent_element = xml_parent_element end |
Instance Attribute Details
#element_tag ⇒ Object (readonly)
Returns the value of attribute element_tag.
3 4 5 |
# File 'lib/lazy_xml_model/element_proxy.rb', line 3 def element_tag @element_tag end |
#xml_document ⇒ Object (readonly)
Returns the value of attribute xml_document.
3 4 5 |
# File 'lib/lazy_xml_model/element_proxy.rb', line 3 def xml_document @xml_document end |
#xml_parent_element ⇒ Object (readonly)
Returns the value of attribute xml_parent_element.
3 4 5 |
# File 'lib/lazy_xml_model/element_proxy.rb', line 3 def xml_parent_element @xml_parent_element end |
Instance Method Details
#value ⇒ Object
Getter Method
12 13 14 15 16 |
# File 'lib/lazy_xml_model/element_proxy.rb', line 12 def value if xml_element.present? xml_element.children.first.content end end |
#value=(value) ⇒ Object
Setter Method
19 20 21 22 23 24 25 26 27 |
# File 'lib/lazy_xml_model/element_proxy.rb', line 19 def value=(value) if xml_element.present? xml_element.children.first.content = value else xml_element = Nokogiri::XML::Element.new(element_tag.to_s, xml_document) xml_element.content = value xml_parent_element.add_child(xml_element) end end |