Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/refx/engine/p3lib/p3lib_hash_from_xml.rb

Constant Summary collapse

XML_PARSING =
{
  "symbol"       => Proc.new  { |symbol|  symbol.to_sym },
  "date"         => Proc.new  { |date|    ::Date.parse(date) },
  "datetime"     => Proc.new  { |time|    ::Time.parse(time).utc },
  "integer"      => Proc.new  { |integer| integer.to_i },
  "float"        => Proc.new  { |float|   float.to_f },
  "decimal"      => Proc.new  { |number|  BigDecimal(number) },
  "boolean"      => Proc.new  { |boolean| %w(1 true).include?(boolean.strip) },
  "string"       => Proc.new  { |string|  string.to_s },
  "yaml"         => Proc.new  { |yaml|    YAML::load(yaml) rescue yaml },
  "base64Binary" => Proc.new  { |bin|     Base64.decode64(bin) },
  # FIXME: Get rid of eval and institute a proper decorator here
  "file"         => Proc.new do |file, entity|
    f = StringIO.new(Base64.decode64(file))
    eval "def f.original_filename() '#{entity["name"]}' || 'untitled' end"
    eval "def f.content_type()      '#{entity["content_type"]}' || 'application/octet-stream' end"
    f
  end
}

Class Method Summary collapse

Class Method Details

.from_xml(xml, preserve_attributes = false) ⇒ Object



40
41
42
# File 'lib/refx/engine/p3lib/p3lib_hash_from_xml.rb', line 40

def self.from_xml(xml, preserve_attributes = false)
  typecast_xml_value(self.undasherize_keys(XmlSimple.xml_in(xml,'forcearray'=>false,'forcecontent'=>true,'keeproot'=>true,'contentkey'=>'__content__')), preserve_attributes)
end