Class: Mercy::PeriodParser
- Inherits:
-
Object
- Object
- Mercy::PeriodParser
- Defined in:
- lib/mercy/period_parser.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(period) ⇒ PeriodParser
constructor
A new instance of PeriodParser.
- #to_seconds ⇒ Object
Constructor Details
#initialize(period) ⇒ PeriodParser
Returns a new instance of PeriodParser.
11 12 13 |
# File 'lib/mercy/period_parser.rb', line 11 def initialize(period) @period = period end |
Class Method Details
.parse(period) ⇒ Object
4 5 6 7 8 |
# File 'lib/mercy/period_parser.rb', line 4 def parse(period) return unless period return period if period.is_a?(Integer) new(period).to_seconds end |
Instance Method Details
#to_seconds ⇒ Object
15 16 17 18 |
# File 'lib/mercy/period_parser.rb', line 15 def to_seconds return unless period.match(/^\d+(years|months|days|hours|minutes|seconds)?/) type.blank? ? value.seconds : value.public_send(type) end |