Class: SaxStream::Internal::Mappings::ElementContent

Inherits:
Element
  • Object
show all
Defined in:
lib/sax_stream/internal/mappings/element_content.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Element

#find_or_insert_node, #map_value_onto_object, #string_value_from_object

Methods inherited from Base

#find_or_insert_parent_node, #handler_for, #map_value_onto_object, #path_parts

Constructor Details

#initialize(name, options = {}) ⇒ ElementContent

Returns a new instance of ElementContent.



7
8
9
10
# File 'lib/sax_stream/internal/mappings/element_content.rb', line 7

def initialize(name, options = {})
  @cdata = options[:cdata]
  super
end

Instance Method Details

#update_parent_node(builder, doc, parent, object) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/sax_stream/internal/mappings/element_content.rb', line 12

def update_parent_node(builder, doc, parent, object)
  node = find_or_insert_child_element(doc, parent, path_parts.last)
  value = string_value_from_object(object)
  if @cdata
    node.add_child(Nokogiri::XML::CDATA.new(doc, value))
  else
    node.content = value
  end
  node
end