class XML::Mapping::HashNode
Node factory function synopsis:
hash_node :_attrname_, _per_hashelement_path_, _key_path_ [, :default_value=>_obj_] [, :optional=>true] [, :class=>_c_] [, :marshaller=>_proc_] [, :unmarshaller=>_proc_] [, :mapping=>_m_] [, :sub_mapping=>_sm_]
-
or -
hash_node :attrname, base_path, per_hashelement_path, key_path
[keyword args the same]
Node that maps a sequence of sub-nodes of the XML tree to an attribute containing a hash of Ruby objects, with each hash value mapping to a corresponding member of the sequence of sub-nodes. The (string-valued) hash key associated with a hash value v is mapped to the text of a specific sub-node of v's sub-node.
Analogously to ArrayNode, base_path and per_arrelement_path define the XPath expression that “yields” the sequence of XML nodes, each of which maps to a value in the hash table. Relative to such a node, key_path_ names the node whose text becomes the associated hash key.
Public Class Methods
Initializer. Called with keyword arguments and either 2 or 3 paths; the hindmost path argument passed is delegated to key_path, the preceding path argument is delegated to per_arrelement_path, the path preceding that argument (if present, “” by default) is delegated to base_path. The meaning of the keyword arguments is the same as for ObjectNode.
# File lib/xml/mapping/standard_nodes.rb, line 335 def initialize(*args) path1,path2,path3,*args = super(*args) base_path,per_hashelement_path,key_path = if path3 [path1,path2,path3] else ["",path1,path2] end per_hashelement_path=per_hashelement_path[1..-1] if per_hashelement_path[0]==?/ @base_path = XML::XXPath.new(base_path) @per_hashelement_path = XML::XXPath.new(per_hashelement_path) @key_path = XML::XXPath.new(key_path) @reader_path = XML::XXPath.new(base_path+"/"+per_hashelement_path) args end