Sha256: d4c2758ffb009a93d0820023b6c53022d6802667c0bd2f5f8f7809a6c6278dcb
Contents?: true
Size: 622 Bytes
Versions: 2
Compression:
Stored size: 622 Bytes
Contents
module Mercy class PeriodParser class << self def parse(period) return unless period return period if period.is_a?(Integer) new(period).to_seconds end end def initialize(period) @period = period end def to_seconds return unless period.match(/^\d+(years|months|days|hours|minutes|seconds)?/) type.blank? ? value.seconds : value.public_send(type) end private attr_reader :period def value @period_value ||= period.gsub(/\D+/, '').to_i end def type @period_type ||= period.gsub(/\d+/, '') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mercy-1.6.0 | lib/mercy/period_parser.rb |
mercy-1.5.0 | lib/mercy/period_parser.rb |