Class: Dentaku::AST::Duration::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/dentaku/ast/functions/duration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, unit) ⇒ Value

Returns a new instance of Value.



17
18
19
20
# File 'lib/dentaku/ast/functions/duration.rb', line 17

def initialize(value, unit)
  @value = value
  @unit = validate_unit(unit)
end

Instance Attribute Details

#unitObject (readonly)

Returns the value of attribute unit.



15
16
17
# File 'lib/dentaku/ast/functions/duration.rb', line 15

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



15
16
17
# File 'lib/dentaku/ast/functions/duration.rb', line 15

def value
  @value
end

Instance Method Details

#validate_unit(unit) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/dentaku/ast/functions/duration.rb', line 22

def validate_unit(unit)
  case unit.downcase
  when /years?/ then :year
  when /months?/ then :month
  when /days?/ then :day
  else
    raise Dentaku::ArgumentError.for(:incompatible_type, value: unit, for: Duration),
      "'#{unit || unit.class}' is not a valid duration unit"
  end
end