Class: FIRM::Serializable::XML::HashAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/firm/serializer/xml.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ HashAdapter

Returns a new instance of HashAdapter.



463
464
465
# File 'lib/firm/serializer/xml.rb', line 463

def initialize(xml)
  @xml = xml
end

Instance Method Details

#[](id) ⇒ Object



471
472
473
474
475
# File 'lib/firm/serializer/xml.rb', line 471

def [](id)
  node = @xml.at_xpath(id.to_s)
  node = node ? node.first_element_child : nil
  node ? Serializable::XML.from_xml(node) : nil
end

#[]=(id, value) ⇒ Object



477
478
479
# File 'lib/firm/serializer/xml.rb', line 477

def []=(id, value)
  Serializable::XML.to_xml(@xml.add_child(Nokogiri::XML::Node.new(id.to_s, @xml.document)), value)
end

#has_key?(id) ⇒ Boolean

Returns:

  • (Boolean)


467
468
469
# File 'lib/firm/serializer/xml.rb', line 467

def has_key?(id)
  !!@xml.at_xpath(id.to_s)
end