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.
- #numeric(n) ⇒ Object
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 22 23 24 25 26 27 28 |
# 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, 'An AttributeValue may not contain an empty set' if value.empty? raise ValidationException, 'Input collection contains duplicates' if value.uniq! end if ['NS', 'N'].include? @type Array(@value).each do |n| numeric(n) end end if ['S', 'SS'].include? @type Array(value).each do |v| raise ValidationException, 'An AttributeValue may not contain an empty string' if v == '' end end if name == '' raise ValidationException, 'Empty attribute name' 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
55 56 57 58 59 60 61 |
# File 'lib/fake_dynamo/attribute.rb', line 55 def <=>(other) if @type == 'N' @value.to_f <=> other.value.to_f else @value <=> other.value end end |
#==(attribute) ⇒ Object
49 50 51 52 53 |
# File 'lib/fake_dynamo/attribute.rb', line 49 def ==(attribute) @name == attribute.name && @value == attribute.value && @type == attribute.type end |
#as_hash ⇒ Object
45 46 47 |
# File 'lib/fake_dynamo/attribute.rb', line 45 def as_hash { @name => { @type => @value } } end |
#description ⇒ Object
38 39 40 41 42 43 |
# File 'lib/fake_dynamo/attribute.rb', line 38 def description { 'AttributeName' => name, 'AttributeType' => type } end |
#eql?(attribute) ⇒ Boolean
63 64 65 66 67 |
# File 'lib/fake_dynamo/attribute.rb', line 63 def eql?(attribute) return false unless attribute.kind_of? Attribute self == attribute end |
#hash ⇒ Object
69 70 71 |
# File 'lib/fake_dynamo/attribute.rb', line 69 def hash name.hash ^ value.hash ^ type.hash end |
#numeric(n) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/fake_dynamo/attribute.rb', line 30 def numeric(n) begin Float(n) rescue raise ValidationException, "The parameter cannot be converted to a numeric value: #{n}" end end |