Class: XML::Mapping::BooleanNode
- Inherits:
-
SingleAttributeNode
- Object
- Node
- SingleAttributeNode
- XML::Mapping::BooleanNode
- Defined in:
- lib/xml/mapping/standard_nodes.rb
Overview
Node factory function synopsis:
boolean_node :_attrname_, _path_,
_true_value_, _false_value_ [, :default_value=>_obj_]
[, :optional=>true]
[, :mapping=>_m_]
Node that maps an XML node’s text (the element name resp. the attribute value) to a boolean attribute of the mapped object. The attribute named by :attrname is mapped to/from the XML subnode named by the XPath expression path. true_value is the text the node must have in order to represent the true boolean value, false_value (actually, any value other than true_value) is the text the node must have in order to represent the false boolean value.
Instance Method Summary collapse
-
#extract_attr_value(xml) ⇒ Object
:nodoc:.
-
#initialize(*args) ⇒ BooleanNode
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) ⇒ BooleanNode
Initializer.
197 198 199 200 201 202 |
# File 'lib/xml/mapping/standard_nodes.rb', line 197 def initialize(*args) path,true_value,false_value,*args = super(*args) @path = XML::XXPath.new(path) @true_value = true_value; @false_value = false_value args end |
Instance Method Details
#extract_attr_value(xml) ⇒ Object
:nodoc:
203 204 205 |
# File 'lib/xml/mapping/standard_nodes.rb', line 203 def extract_attr_value(xml) # :nodoc: default_when_xpath_err{ @path.first(xml).text==@true_value } end |
#set_attr_value(xml, value) ⇒ Object
:nodoc:
206 207 208 |
# File 'lib/xml/mapping/standard_nodes.rb', line 206 def set_attr_value(xml, value) # :nodoc: @path.first(xml,:ensure_created=>true).text = value ? @true_value : @false_value end |