Module: DataBindings::Adapters::XML::Convert

Includes:
ConverterHelper, GemRequirement
Defined in:
lib/data_bindings/adapters/xml.rb

Overview

Creates a String repsentation of a Ruby Hash or Array.

Returns:

  • (String)

    The JSON representation of this object

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConverterHelper

included

Methods included from GemRequirement

gentle_require_gem, included

Class Method Details

.construct(generator, name, obj, builder = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/data_bindings/adapters/xml.rb', line 49

def self.construct(generator, name, obj, builder = nil)
  root = builder.nil?
  builder ||= Builder::XmlMarkup.new
  builder.instruct!(:xml, :encoding => "UTF-8") if root
  case obj
  when Array
    builder.__send__(name || "doc") do |b|
      obj.each_with_index(o, i)
      construct(generator, i.to_s, o, b)
    end
  when Hash
    builder.__send__(name || "doc") do |b|
      obj.each do |k, v|
        construct(generator, k, v, b)
      end
    end
  else
    builder.__send__(name, obj)
  end
  builder.target! if root
end

Instance Method Details

#force_convert_to_xmlObject



43
44
45
# File 'lib/data_bindings/adapters/xml.rb', line 43

def force_convert_to_xml
  Convert.construct(@generator, @name, self, @binding_block)
end