Module: Wheneverd::Interval
- Defined in:
- lib/wheneverd/interval.rb
Overview
Parser for compact interval strings used by the DSL.
The supported format is "<n>s|m|h|d|w", for example "5m" or "1h".
Constant Summary collapse
- MULTIPLIERS =
{ "s" => 1, "m" => 60, "h" => 60 * 60, "d" => 60 * 60 * 24, "w" => 60 * 60 * 24 * 7 }.freeze
- FORMAT =
/\A(?<n>-?\d+)(?<unit>[smhdw])\z/.freeze
Class Method Summary collapse
-
.parse(str) ⇒ Integer
Parse an interval string into seconds.
Class Method Details
.parse(str) ⇒ Integer
Parse an interval string into seconds.
23 24 25 26 27 28 |
# File 'lib/wheneverd/interval.rb', line 23 def self.parse(str) input = normalize_input(str) match = parse_match(input) n = parse_number(match[:n], input) n * MULTIPLIERS.fetch(match[:unit]) end |