Class: XML::Mapping::ObjectNode
- Inherits:
-
SubObjectBaseNode
- Object
- Node
- SingleAttributeNode
- SubObjectBaseNode
- XML::Mapping::ObjectNode
- Defined in:
- lib/xml/mapping/standard_nodes.rb
Overview
Node factory function synopsis:
object_node :_attrname_, _path_ [, :default_value=>_obj_]
[, :optional=>true]
[, :class=>_c_]
[, :marshaller=>_proc_]
[, :unmarshaller=>_proc_]
Node that maps a subtree in the source XML to a Ruby object. :attrname and path are again the attribute name resp. XPath expression of the mapped attribute; the keyword arguments :default_value and :optional are handled by the SingleAttributeNode superclass. The XML subnode named by path is mapped to the attribute named by :attrname according to the keyword arguments :class, :marshaller, and :unmarshaller, which are handled by the SubObjectBaseNode superclass.
Instance Method Summary collapse
-
#extract_attr_value(xml) ⇒ Object
:nodoc:.
-
#initialize_impl(path) ⇒ Object
Initializer.
-
#set_attr_value(xml, value) ⇒ Object
:nodoc:.
Methods inherited from SingleAttributeNode
#default_when_xpath_err, #initialize, #obj_initializing, #obj_to_xml, #xml_to_obj
Methods inherited from Node
#initialize, #obj_initializing, #obj_to_xml, #xml_to_obj
Constructor Details
This class inherits a constructor from XML::Mapping::SingleAttributeNode
Instance Method Details
#extract_attr_value(xml) ⇒ Object
:nodoc:
147 148 149 |
# File 'lib/xml/mapping/standard_nodes.rb', line 147 def extract_attr_value(xml) # :nodoc: @options[:unmarshaller].call(default_when_xpath_err{@path.first(xml)}) end |
#initialize_impl(path) ⇒ Object
Initializer. path (a string denoting an XPath expression) is the location of the subtree.
143 144 145 146 |
# File 'lib/xml/mapping/standard_nodes.rb', line 143 def initialize_impl(path) super @path = XML::XXPath.new(path) end |
#set_attr_value(xml, value) ⇒ Object
:nodoc:
150 151 152 |
# File 'lib/xml/mapping/standard_nodes.rb', line 150 def set_attr_value(xml, value) # :nodoc: @options[:marshaller].call(@path.first(xml,:ensure_created=>true), value) end |