Module: AWS::DynamoDB::Types

Instance Method Summary collapse

Instance Method Details

#format_attribute_value(value, context = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/aws/dynamo_db/types.rb', line 43

def format_attribute_value(value, context = nil)
  indicator = type_indicator(value, context)

  value = [] if value == :empty_number_set
  value = value.to_s if indicator == :n
  value = value.map(&:to_s) if indicator == :ns

  Hash[[[indicator, value]]]
end

#value_from_response(hash) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aws/dynamo_db/types.rb', line 23

def value_from_response(hash)
  (type, value) = hash.to_a.first
  case type
  when "S", :s
    value
  when "SS", :ss
    Set[*value]
  when "N", :n
    BigDecimal(value.to_s)
  when "NS", :ns
    Set[*value.map { |v| BigDecimal(v.to_s) }]
  end
end

#values_from_response_hash(hash) ⇒ Object



37
38
39
40
41
# File 'lib/aws/dynamo_db/types.rb', line 37

def values_from_response_hash(hash)
  hash.inject({}) do |h, (key, value_hash)|
    h.update(key => value_from_response(value_hash))
  end
end