Class: FakeDynamo::Attribute
- Inherits:
-
Object
- Object
- FakeDynamo::Attribute
- Defined in:
- lib/fake_dynamo/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(attribute) ⇒ Object
- #as_hash ⇒ Object
- #description ⇒ Object
- #eql?(attribute) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name, value, type) ⇒ Attribute
constructor
A new instance of Attribute.
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
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/fake_dynamo/attribute.rb', line 3 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/fake_dynamo/attribute.rb', line 3 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/fake_dynamo/attribute.rb', line 3 def value @value end |
Class Method Details
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_hash ⇒ Object
30 31 32 |
# File 'lib/fake_dynamo/attribute.rb', line 30 def as_hash { @name => { @type => @value } } end |
#description ⇒ Object
23 24 25 26 27 28 |
# File 'lib/fake_dynamo/attribute.rb', line 23 def description { 'AttributeName' => name, 'AttributeType' => type } end |
#eql?(attribute) ⇒ 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 |
#hash ⇒ Object
54 55 56 |
# File 'lib/fake_dynamo/attribute.rb', line 54 def hash name.hash ^ value.hash ^ type.hash end |