Class: Dentaku::AST::Duration::Value
- Inherits:
-
Object
- Object
- Dentaku::AST::Duration::Value
- Defined in:
- lib/dentaku/ast/functions/duration.rb
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, unit) ⇒ Value
constructor
A new instance of Value.
- #validate_unit(unit) ⇒ Object
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
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
15 16 17 |
# File 'lib/dentaku/ast/functions/duration.rb', line 15 def unit @unit end |
#value ⇒ Object (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 |