Rename to Crono

This commit is contained in:
Dzmitry Plashchynski
2015-03-03 13:51:40 +02:00
parent 6b185c44ac
commit 3652e9525a
18 changed files with 45 additions and 45 deletions

24
lib/crono/period.rb Normal file
View File

@@ -0,0 +1,24 @@
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