Sha256: 1c131c1cb8080a299b42fe786abfa15af867b72ea524c5181aca785da64a6789

Contents?: true

Size: 673 Bytes

Versions: 1

Compression:

Stored size: 673 Bytes

Contents

module Crono
  class Period
    def initialize(period, at: nil)
      @period = period
      @at_hour, @at_min = parse_at(at) if at
    end

    def next(since: nil)
      since ||= Time.now
      @period.since(since).change({hour: @at_hour, min: @at_min}.compact)
    end

    def description
      desc = "every #{@period.inspect}"
      desc += " at %.2i:%.2i" % [@at_hour, @at_min] if @at_hour && @at_min
      desc
    end

    def parse_at(at)
      case at
      when String
        time = Time.parse(at)
        return time.hour, time.min
      when Hash
        return at[:hour], at[:min]
      else
        raise "Unknown 'at' format"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crono-0.6.1 lib/crono/period.rb