Class: Foscam::Schedule::ThirdOfADay

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bit) ⇒ ThirdOfADay

Returns a new instance of ThirdOfADay.

Parameters:

  • bit (Fixnum)

    The 32-bit bitmask representing 8 hours divided into 15 minute blocks



10
11
12
# File 'lib/foscam/schedule/third_of_a_day.rb', line 10

def initialize(bit)
	self.bit = bit
end

Instance Attribute Details

#bitObject

Returns the value of attribute bit.



6
7
8
# File 'lib/foscam/schedule/third_of_a_day.rb', line 6

def bit
  @bit
end

Instance Method Details

#active?(idx) ⇒ FalseClass, TrueClass

Returns whether the bit is positive or not

Parameters:

  • idx (Fixnum)

    The bit index representing the 15 minute block

Returns:

  • (FalseClass, TrueClass)

    Whether the bit is equal to 1



18
19
20
# File 'lib/foscam/schedule/third_of_a_day.rb', line 18

def active?(idx)
	binary_string[31-idx].to_i > 0
end

#to_hashHash

Convert the bitmask representing a third of a day with a Hash. The key is the idx of the bit and the value is a boolean of whether it is active or not

Returns:

  • (Hash)


25
26
27
28
29
30
31
32
33
# File 'lib/foscam/schedule/third_of_a_day.rb', line 25

def to_hash
	h = {}
	i = 0
	binary_string.reverse.each_char do |char|
		h.merge!({i => char.to_i > 0})
		i = i + 1
	end
	h
end