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_]
[, :mapping=>_m_]
[, :sub_mapping=>_sm_]
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(*args) ⇒ ObjectNode
constructor
Initializer.
-
#set_attr_value(xml, value) ⇒ Object
:nodoc:.
Methods inherited from SingleAttributeNode
#default_when_xpath_err, #initialize_impl, #is_present_in?, #obj_initializing, #obj_to_xml, #xml_to_obj
Methods inherited from Node
#is_present_in?, #obj_initializing, #obj_to_xml, #xml_to_obj
Constructor Details
#initialize(*args) ⇒ ObjectNode
Initializer. path (a string denoting an XPath expression) is the location of the subtree.
167 168 169 170 171 |
# File 'lib/xml/mapping/standard_nodes.rb', line 167 def initialize(*args) path,*args = super(*args) @path = XML::XXPath.new(path) args end |
Instance Method Details
#extract_attr_value(xml) ⇒ Object
:nodoc:
172 173 174 |
# File 'lib/xml/mapping/standard_nodes.rb', line 172 def extract_attr_value(xml) # :nodoc: @unmarshaller.call(default_when_xpath_err{@path.first(xml)}) end |
#set_attr_value(xml, value) ⇒ Object
:nodoc:
175 176 177 |
# File 'lib/xml/mapping/standard_nodes.rb', line 175 def set_attr_value(xml, value) # :nodoc: @marshaller.call(@path.first(xml,:ensure_created=>true), value) end |