Class: FIRM::Serializable::XML::HashAdapter
- Inherits:
-
Object
- Object
- FIRM::Serializable::XML::HashAdapter
- Defined in:
- lib/firm/serializer/xml.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, value) ⇒ Object
- #has_key?(id) ⇒ Boolean
-
#initialize(xml) ⇒ HashAdapter
constructor
A new instance of HashAdapter.
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
467 468 469 |
# File 'lib/firm/serializer/xml.rb', line 467 def has_key?(id) !!@xml.at_xpath(id.to_s) end |