Class: Representable::XML::TextBinding

Inherits:
Binding
  • Object
show all
Defined in:
lib/representable/bindings/xml_bindings.rb

Overview

Represents text content in a tag. # FIXME: is this tested???

Instance Attribute Summary

Attributes inherited from Binding

#definition

Instance Method Summary collapse

Methods inherited from Binding

#initialize, #read

Constructor Details

This class inherits a constructor from Representable::XML::Binding

Instance Method Details

#write(xml, value) ⇒ Object

Updates the text in the given xml block to the value provided.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/representable/bindings/xml_bindings.rb', line 63

def write(xml, value)
  wrap(xml).tap do |xml|
    if definition.content?
      add(xml, value)
    elsif definition.name?
      xml.name = value
    elsif definition.array?
      value.each do |v|
        add(xml.add_node(definition.from), v)
      end
    else
      add(xml.add_node(definition.from), value)
    end
  end
end