class Rushour::TimeManager
Public Class Methods
new()
click to toggle source
# File lib/rushour/time_manager.rb, line 3 def initialize @intervals = Rushour::Settings.intervals.map do |interval| Rushour::Interval.new(Rushour::Daytime.from_str(interval[:start]), Rushour::Daytime.from_str(interval[:finish])) end end
Public Instance Methods
check()
click to toggle source
# File lib/rushour/time_manager.rb, line 10 def check now = Rushour::Daytime.now if @intervals.any? { |interval| interval.in?(now) } @on_start_hook.call unless @in_interval || @in_interval == nil @in_interval = true else @on_finish_hook.call if @in_interval || @in_interval == nil @in_interval = false end end
on_finish(&block)
click to toggle source
# File lib/rushour/time_manager.rb, line 25 def on_finish(&block) @on_finish_hook = block end
on_start(&block)
click to toggle source
# File lib/rushour/time_manager.rb, line 21 def on_start(&block) @on_start_hook = block end