Class: FakeDynamo::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_dynamo/attribute.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, type) ⇒ Attribute

Returns a new instance of Attribute.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fake_dynamo/attribute.rb', line 5

def initialize(name, value, type)
  @name, @value, @type = name, value, type

  if ['NS', 'SS'].include? @type
    raise ValidationException, 'Input collection contains duplicates' if value.uniq!
  end

  if ['NS', 'N'].include? @type
    Array(@value).each do |n|
      begin
        Integer(n)
      rescue
        raise ValidationException, "The parameter cannot be converted to a numeric value: #{n}"
      end
    end
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/fake_dynamo/attribute.rb', line 3

def name
  @name
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/fake_dynamo/attribute.rb', line 3

def type
  @type
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/fake_dynamo/attribute.rb', line 3

def value
  @value
end

Class Method Details

.from_data(data) ⇒ Object



59
60
61
# File 'lib/fake_dynamo/attribute.rb', line 59

def from_data(data)
  Attribute.new(data['AttributeName'], nil, data['AttributeType'])
end

.from_hash(name, hash) ⇒ Object



63
64
65
# File 'lib/fake_dynamo/attribute.rb', line 63

def from_hash(name, hash)
  Attribute.new(name, hash.values.first, hash.keys.first)
end

Instance Method Details

#<=>(other) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/fake_dynamo/attribute.rb', line 40

def <=>(other)
  if @type == 'N'
    @value.to_i <=> other.value.to_i
  else
    @value <=> other.value
  end
end

#==(attribute) ⇒ Object



34
35
36
37
38
# File 'lib/fake_dynamo/attribute.rb', line 34

def ==(attribute)
  @name == attribute.name &&
    @value == attribute.value &&
    @type == attribute.type
end

#as_hashObject



30
31
32
# File 'lib/fake_dynamo/attribute.rb', line 30

def as_hash
  { @name => { @type => @value } }
end

#descriptionObject



23
24
25
26
27
28
# File 'lib/fake_dynamo/attribute.rb', line 23

def description
  {
    'AttributeName' => name,
    'AttributeType' => type
  }
end

#eql?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/fake_dynamo/attribute.rb', line 48

def eql?(attribute)
  return false unless attribute.kind_of? Attribute

  self == attribute
end

#hashObject



54
55
56
# File 'lib/fake_dynamo/attribute.rb', line 54

def hash
  name.hash ^ value.hash ^ type.hash
end