Module: Angus::Unmarshalling

Defined in:
lib/angus/marshallings/unmarshalling.rb

Class Method Summary collapse

Class Method Details

.unmarshal_scalar(scalar, type) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/angus/marshallings/unmarshalling.rb', line 7

def self.unmarshal_scalar(scalar, type)
  return nil if scalar.nil?

  case type
  when :string
    scalar
  when :integer
    scalar
  when :boolean
    scalar
  when :date
    Date.iso8601(scalar)
  when :date_time
    DateTime.iso8601(scalar)
  when :decimal
    BigDecimal.new(scalar.to_s)
  else
    raise ArgumentError, "Unknown type: #{type}"
  end
end