Class: XML::Mapping::TextNode

Inherits:
SingleAttributeNode show all
Defined in:
lib/xml/mapping/standard_nodes.rb

Overview

Node factory function synopsis:

text_node :_attrname_, _path_ [, :default_value=>_obj_]
                              [, :optional=>true]
                              [, :mapping=>_m_]

Node that maps an XML node’s text (the element’s first child text node resp. the attribute’s value) to a (string) attribute of the mapped object. path (an XPath expression) locates the XML node, attrname (a symbol) names the attribute. :default_value is the default value, :optional=>true is equivalent to :default_value=>nil (see superclass documentation for details). m is the mapping; it defaults to the current default mapping

Instance Method Summary collapse

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) ⇒ TextNode

Returns a new instance of TextNode.



23
24
25
26
27
# File 'lib/xml/mapping/standard_nodes.rb', line 23

def initialize(*args)
  path,*args = super(*args)
  @path = XML::XXPath.new(path)
  args
end

Instance Method Details

#extract_attr_value(xml) ⇒ Object

:nodoc:



28
29
30
# File 'lib/xml/mapping/standard_nodes.rb', line 28

def extract_attr_value(xml) # :nodoc:
  default_when_xpath_err{ @path.first(xml).text }
end

#set_attr_value(xml, value) ⇒ Object

:nodoc:



31
32
33
# File 'lib/xml/mapping/standard_nodes.rb', line 31

def set_attr_value(xml, value) # :nodoc:
  @path.first(xml,:ensure_created=>true).text = value
end