module LazyXmlModel

Constants

VERSION

Public Class Methods

parse(xml_string) click to toggle source

Class Methods

# File lib/lazy_xml_model.rb, line 29
def self.parse(xml_string)
  object = self.new
  object.xml_document = Nokogiri::XML::Document.parse(xml_string, &:noblanks)
  object
end

Public Instance Methods

delete() click to toggle source
# File lib/lazy_xml_model.rb, line 56
def delete
  xml_element.remove
end
to_xml() click to toggle source
# File lib/lazy_xml_model.rb, line 51
def to_xml
  # TODO: Make this work for non-root objects
  xml_document.to_xml(indent: 2, encoding: 'UTF-8')
end
xml_document() click to toggle source

Instance Methods

# File lib/lazy_xml_model.rb, line 39
def xml_document
  @xml_document ||= Nokogiri::XML::Document.parse("<#{root_tag}/>", &:noblanks)
end
xml_element() click to toggle source
# File lib/lazy_xml_model.rb, line 47
def xml_element
  @xml_element ||= xml_document.root
end
xml_parent_element() click to toggle source
# File lib/lazy_xml_model.rb, line 43
def xml_parent_element
  @xml_parent_element
end

Private Instance Methods

root_tag() click to toggle source
# File lib/lazy_xml_model.rb, line 62
def root_tag
  self.tag || self.class.name.demodulize.downcase
end