Flowdock
method

typecast_xml_value

Importance_0
v1.2.6 - Show latest stable - 0 notes - Class: ActiveSupport::CoreExtensions::Hash::Conversions::ClassMethods
  • 1.0.0
  • 1.1.6
  • 1.2.6 (0)
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0
  • 3.0.9
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2
  • What's this?
typecast_xml_value(value) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activesupport/lib/active_support/core_ext/hash/conversions.rb, line 143
            def typecast_xml_value(value)
              case value.class.to_s
                when "Hash"
                  if value.has_key?("__content__")
                    content = translate_xml_entities(value["__content__"])
                    case value["type"]
                      when "integer"  then content.to_i
                      when "boolean"  then content.strip == "true"
                      when "datetime" then ::Time.parse(content).utc
                      when "date"     then ::Date.parse(content)
                      else                 content
                    end
                  else
                    (value.blank? || value['type'] || value['nil'] == 'true') ? nil : value.inject({}) do |h,(k,v)|
                      h[k] = typecast_xml_value(v)
                      h
                    end
                  end
                when "Array"
                  value.map! { |i| typecast_xml_value(i) }
                  case value.length
                    when 0 then nil
                    when 1 then value.first
                    else value
                  end
                when "String"
                  value
                else
                  raise "can't typecast #{value.inspect}"
              end
            end
Register or log in to add new notes.