Class: Foscam::Schedule::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/foscam/schedule/day.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bit1, bit2, bit3) ⇒ Day

Returns a new instance of Day.

Parameters:

  • bit1 (Fixnum)

    The 32-bit bitmask representing the first third of the day

  • bit2 (Fixnum)

    The 32-bit bitmask representing the second third of the day

  • bit3 (Fixnum)

    The 32-bit bitmask representing the last third of the 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

#bitsObject

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

Parameters:

  • time (Time, Fixnum, DateTime)

    Accepts multiple forms of time. If a Datetime or Time is used then only the time of day is used. If a fixnum is given then it is a number representing the number of seconds from the start of the day.

Returns:

  • (FalseClass, TrueClass)

    Whether it is busy at that 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_hashHash

Convert the Week to a nested hash with the day of the week as the key and and time as the second key

Returns:

  • (Hash)


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