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.
466 467 468 |
# File 'lib/firm/serializer/xml.rb', line 466 def initialize(xml) @xml = xml end |
Instance Method Details
#[](id) ⇒ Object
474 475 476 477 478 |
# File 'lib/firm/serializer/xml.rb', line 474 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
480 481 482 |
# File 'lib/firm/serializer/xml.rb', line 480 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
470 471 472 |
# File 'lib/firm/serializer/xml.rb', line 470 def has_key?(id) !!@xml.at_xpath(id.to_s) end |