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

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

Instance Attribute Summary

Attributes inherited from Binding

#cached_representer, #getter, #name, #setter

Instance Method Summary collapse

Methods included from Binding::Collection

#skipable_empty_value?

Methods inherited from Representable::XML::Binding

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

Methods inherited from Binding

#[], build, #default_for, #initialize, #skipable_empty_value?

Methods included from Binding::Factories

#collect_for, #default_parse_fragment_functions, #default_parse_init_functions, #default_post_functions, #default_render_fragment_functions, #default_render_init_functions, #parse_functions, #pipeline_for, #render_functions

Methods included from Binding::EvaluateOption

#evaluate_option

Methods included from Binding::Deprecatable

#compile_fragment, #uncompile_fragment

Constructor Details

This class inherits a constructor from Representable::Binding

Instance Method Details

#deserialize_from(nodes) ⇒ Object



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

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

  hash
end

#serialize_for(value, parent, as) ⇒ Object



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

def serialize_for(value, parent, as)
  set_for(parent, value.collect do |k, v|
    node = XML::Node(parent, k)
    serialize_node(node, v, as)
  end)
end