Class: Flipper::Expressions::Duration
- Inherits:
-
Object
- Object
- Flipper::Expressions::Duration
- Defined in:
- lib/flipper/expressions/duration.rb
Constant Summary collapse
- SECONDS_PER =
{ "second" => 1, "minute" => 60, "hour" => 3600, "day" => 86400, "week" => 604_800, "month" => 2_629_746, # 1/12 of a gregorian year "year" => 31_556_952 # length of a gregorian year (365.2425 days) }.freeze
Class Method Summary collapse
Class Method Details
.call(scalar, unit = 'second') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/flipper/expressions/duration.rb', line 14 def self.call(scalar, unit = 'second') unit = unit.to_s.downcase.chomp("s") unless scalar.is_a?(Numeric) raise ArgumentError.new("Duration value must be a number but was #{scalar.inspect}") end unless SECONDS_PER[unit] raise ArgumentError.new("Duration unit #{unit.inspect} must be one of: #{SECONDS_PER.keys.join(', ')}") end scalar * SECONDS_PER[unit] end |