Class: Schedule::Period

Inherits:
Object show all
Defined in:
lib/abstractivator/schedule/schedule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start, stop) ⇒ Period

Returns a new instance of Period.



53
54
55
56
# File 'lib/abstractivator/schedule/schedule.rb', line 53

def initialize(start, stop)
  @start = start
  @stop = stop
end

Instance Attribute Details

#startObject

inclusive



50
51
52
# File 'lib/abstractivator/schedule/schedule.rb', line 50

def start
  @start
end

#stopObject

exclusive



51
52
53
# File 'lib/abstractivator/schedule/schedule.rb', line 51

def stop
  @stop
end

Instance Method Details

#includes?(localtime) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/abstractivator/schedule/schedule.rb', line 58

def includes?(localtime)
  wmin = Wmin.from_localtime(localtime)
  result = start <= wmin && wmin < stop
  #puts "#{to_s} includes? #{to_clock(wmin)} (#{localtime}) : #{result}"
  #puts "  #{start} <= #{wmin} && #{wmin} < #{stop}"
  result
end

#to_clock(wmin) ⇒ Object



70
71
72
73
74
# File 'lib/abstractivator/schedule/schedule.rb', line 70

def to_clock(wmin)
  day = (wmin / Wmin::DAY) % 7
  minutes = wmin % Wmin::DAY
  "#{minutes / 60}:#{minutes % 60}#{WEEKDAYS[day]}"
end

#to_sObject



66
67
68
# File 'lib/abstractivator/schedule/schedule.rb', line 66

def to_s
  "#{to_clock(start)}-#{to_clock(stop)}"
end