Class: Feedbook::Helpers::TimeIntervalParser
- Inherits:
-
Object
- Object
- Feedbook::Helpers::TimeIntervalParser
- Defined in:
- lib/feedbook/helpers/time_interval_parser.rb
Constant Summary collapse
- INTERVAL_FORMAT =
/\A(\d+)(s|m|h|d)\z/
Class Method Summary collapse
-
.parse(value) ⇒ Integer
Parses given string with interval and converts into a amount of seconds.
Class Method Details
.parse(value) ⇒ Integer
Parses given string with interval and converts into a amount of seconds.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/feedbook/helpers/time_interval_parser.rb', line 15 def self.parse(value) if value.strip =~ INTERVAL_FORMAT number, type = INTERVAL_FORMAT.match(value).captures case type when 's' Integer(number).seconds when 'm' Integer(number).minutes when 'h' Integer(number).hours when 'd' Integer(number).days end else raise ArgmumentError.new end rescue raise Errors::InvalidIntervalFormatError.new end |