Sha256: e000e6d0efa86e30c6f7e99f1d8bdcb45daaeea5a754fd34aa8fc1d35f9c00ad
Contents?: true
Size: 621 Bytes
Versions: 11
Compression:
Stored size: 621 Bytes
Contents
module Bidu 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
11 entries across 11 versions & 3 rubygems