Class: Representable::XML::Binding::Hash

Inherits:
Collection show all
Includes:
Binding::Hash
Defined in:
lib/representable/xml/binding.rb

Instance Attribute Summary

Attributes inherited from Binding

#represented, #user_options

Instance Method Summary collapse

Methods inherited from Representable::XML::Binding

build_for, #deserialize_method, #read, #serialize_method, #serialize_node, #write

Methods inherited from Binding

#[], #array?, #as, build, #compile_fragment, #default_for, #evaluate_option, #get, #getter, #has_default?, #initialize, #name, #parse_filter, #read_fragment, #render_filter, #render_fragment, #representable?, #representer_module, #representer_module_for, #set, #setter, #skipable_empty_value?, #typed?, #uncompile_fragment, #write_fragment

Constructor Details

This class inherits a constructor from Representable::Binding

Instance Method Details

#deserialize_from(nodes) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/representable/xml/binding.rb', line 114

def deserialize_from(nodes)
  hash = {}
  nodes.children.each do |node|
    hash[node.name] = content_for node
  end

  hash
end

#serialize_for(value, parent) ⇒ Object



107
108
109
110
111
112
# File 'lib/representable/xml/binding.rb', line 107

def serialize_for(value, parent)
  set_for(parent, value.collect do |k, v|
    node = node_for(parent, k)
    serialize_node(node, v)
  end)
end