Sha256: 14ab2157a4d11c0b66184cd2c6359e25351d9bf6304e5e7a7860b4116c29bef4

Contents?: true

Size: 477 Bytes

Versions: 2

Compression:

Stored size: 477 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
      @period.from_now.change({hour: @at_hour, min: @at_min}.compact)
    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

2 entries across 2 versions & 1 rubygems

Version Path
crono-0.5.1 lib/crono/period.rb
crono-0.5.0 lib/crono/period.rb