Class: Aws::DynamoDB::AttributeDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/dynamodb/attribute_deserializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(hash) ⇒ Object



6
7
8
# File 'lib/aws/dynamodb/attribute_deserializer.rb', line 6

def self.call(hash)
  new.call(hash)
end

Instance Method Details

#call(hash) ⇒ Object



10
11
12
13
14
# File 'lib/aws/dynamodb/attribute_deserializer.rb', line 10

def call(hash)
  return unless hash.is_a?(Hash)

  hash.transform_values { |v| translate(v) }
end

#translate(arg) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aws/dynamodb/attribute_deserializer.rb', line 16

def translate(arg)
  type = arg.keys[0]
  value = arg[type]
  case type
  when 'N' then BigDecimal(value)
  when 'L'
    value.map { |item| translate(item) }
  when 'SS'
    Set.new(value)
  when 'NS'
    Set.new(value.map(&:to_s))
  when 'M'
    value.transform_values { |item| translate(item) }
  when 'S' then value.to_s
  when 'B' then StringIO.new(Base64.decode64(value))
  when 'BS'
    Set.new(value.map { |item| StringIO.new(Base64.decode64(item)) })
  when 'NULL' then nil
  when 'BOOL' then value
  else value
  end
end