class Ecommerce::AttributeHandler
Constants
- KINDS
Attributes
attribute[R]
Public Class Methods
handle(attribute)
click to toggle source
# File lib/ecommerce/attribute_handler.rb, line 14 def self.handle(attribute) self.new(attribute).handle end
new(attribute)
click to toggle source
# File lib/ecommerce/attribute_handler.rb, line 10 def initialize(attribute) @attribute = attribute end
Public Instance Methods
handle()
click to toggle source
# 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
Private Instance Methods
as_date()
click to toggle source
# File lib/ecommerce/attribute_handler.rb, line 43 def as_date Date.parse(attribute) end
as_datetime()
click to toggle source
# File lib/ecommerce/attribute_handler.rb, line 47 def as_datetime DateTime.parse(attribute) end
as_decimal()
click to toggle source
# File lib/ecommerce/attribute_handler.rb, line 39 def as_decimal BigDecimal.new(attribute) end
is_date?()
click to toggle source
# File lib/ecommerce/attribute_handler.rb, line 31 def is_date? attribute =~ /\A\d+{4}\-\d+{2}\-\d+{2}\Z/ end
is_datetime?()
click to toggle source
# File lib/ecommerce/attribute_handler.rb, line 35 def is_datetime? attribute =~ /\A\d+{4}\-\d+{2}\-\d+{2}[T ]?\d+{2}\:\d+{2}\:\d+{2}[Z]?\Z/ end
is_decimal?()
click to toggle source
# File lib/ecommerce/attribute_handler.rb, line 27 def is_decimal? attribute =~ /\A\d+\.\d+\Z/ end