Class: LazyXmlModel::ElementProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_xml_model/element_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tagObject (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_documentObject (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_elementObject (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

#valueObject

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