Module: XMLConverters

Included in:
HashConverters
Defined in:
lib/kalibro_gem/helpers/xml_converters.rb

Instance Method Summary collapse

Instance Method Details

#get_xml(field, field_value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kalibro_gem/helpers/xml_converters.rb', line 9

def get_xml(field, field_value)
  hash = Hash.new
  if field_value.is_a?(KalibroGem::Entities::Model)
    hash = {:attributes! => {}}
    hash[:attributes!][field.to_sym] = {
      'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
      'xsi:type' => 'kalibro:' + xml_instance_class_name(field_value)
    }
  end
  hash
end

#xml_instance_class_name(object) ⇒ Object



2
3
4
5
6
7
# File 'lib/kalibro_gem/helpers/xml_converters.rb', line 2

def xml_instance_class_name(object)
  xml_name = object.class.name
  xml_name["KalibroGem::Entities::"] = "" if xml_name.start_with?("KalibroGem::Entities::")
  xml_name[0..0] = xml_name[0..0].downcase
  xml_name + "Xml"
end