Class: Ecommerce::AttributeHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/ecommerce/attribute_handler.rb

Constant Summary collapse

KINDS =
[:decimal, :date, :datetime]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ AttributeHandler

Returns a new instance of AttributeHandler.



10
11
12
# File 'lib/ecommerce/attribute_handler.rb', line 10

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



8
9
10
# File 'lib/ecommerce/attribute_handler.rb', line 8

def attribute
  @attribute
end

Class Method Details

.handle(attribute) ⇒ Object



14
15
16
# File 'lib/ecommerce/attribute_handler.rb', line 14

def self.handle(attribute)
  self.new(attribute).handle
end

Instance Method Details

#handleObject



18
19
20
21
22
23
# File 'lib/ecommerce/attribute_handler.rb', line 18

def handle
  KINDS.each do |kind|
    return send("as_#{kind}") if send("is_#{kind}?")
  end
  attribute
end