class Foscam::Schedule::ThirdOfADay

Attributes

bit[RW]

Public Class Methods

new(bit) click to toggle source

@param bit [Fixnum] The 32-bit bitmask representing 8 hours divided into 15 minute blocks

# File lib/foscam/schedule/third_of_a_day.rb, line 10
def initialize(bit)
        self.bit = bit
end

Public Instance Methods

active?(idx) click to toggle source

Returns whether the bit is positive or not @param idx [Fixnum] The bit index representing the 15 minute block @return [FalseClass, TrueClass] Whether the bit is equal to 1

# File lib/foscam/schedule/third_of_a_day.rb, line 18
def active?(idx)
        binary_string[31-idx].to_i > 0
end
to_hash() click to toggle source

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 @return [Hash]

# 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

Private Instance Methods

binary_string() click to toggle source
# File lib/foscam/schedule/third_of_a_day.rb, line 37
def binary_string
        @str ||= ("%032d" % self.bit.to_s(2))
end