Class: Foscam::Schedule::Day
- Inherits:
-
Object
- Object
- Foscam::Schedule::Day
- Defined in:
- lib/foscam/schedule/day.rb
Instance Attribute Summary collapse
-
#bits ⇒ Object
Returns the value of attribute bits.
Instance Method Summary collapse
-
#busy_at?(time) ⇒ FalseClass, TrueClass
Determine if the the schedule is true at the given date time.
-
#initialize(bit1, bit2, bit3) ⇒ Day
constructor
A new instance of Day.
-
#to_hash ⇒ Hash
Convert the Week to a nested hash with the day of the week as the key and and time as the second key.
Constructor Details
#initialize(bit1, bit2, bit3) ⇒ Day
Returns a new instance of Day.
9 10 11 12 13 14 |
# File 'lib/foscam/schedule/day.rb', line 9 def initialize(bit1, bit2, bit3) self.bits = Array.new(3) self.bits[0] = ThirdOfADay.new(bit1) self.bits[1] = ThirdOfADay.new(bit2) self.bits[2] = ThirdOfADay.new(bit3) end |
Instance Attribute Details
#bits ⇒ Object
Returns the value of attribute bits.
16 17 18 |
# File 'lib/foscam/schedule/day.rb', line 16 def bits @bits end |
Instance Method Details
#busy_at?(time) ⇒ FalseClass, TrueClass
Determine if the the schedule is true at the given date time
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/foscam/schedule/day.rb', line 22 def busy_at?(time) case time when Fixnum bit = seconds/28800 bit_num = bit_from_time(seconds/3600, seconds % 3600) when DateTime time = time.to_time bit = time.hour / 8 bit_num = bit_from_time(time.hour, time.min) when Time bit = time.hour / 8 bit_num = bit_from_time(time.hour, time.min) else end self.bits[bit].active?(bit_num) end |
#to_hash ⇒ Hash
Convert the Week to a nested hash with the day of the week as the key and and time as the second key
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/foscam/schedule/day.rb', line 43 def to_hash h = {} self.bits.each_index do |idx| bits[idx].to_hash.each do |j, value| minute = (j % 4) * 15 hour = j / 4 + idx * 8 h.merge!("#{"%02d" % hour}:#{"%02d" % minute}" => value) end end h end |