Class: Foscam::Schedule::ThirdOfADay
- Inherits:
-
Object
- Object
- Foscam::Schedule::ThirdOfADay
- Defined in:
- lib/foscam/schedule/third_of_a_day.rb
Instance Attribute Summary collapse
-
#bit ⇒ Object
Returns the value of attribute bit.
Instance Method Summary collapse
-
#active?(idx) ⇒ FalseClass, TrueClass
Returns whether the bit is positive or not.
-
#initialize(bit) ⇒ ThirdOfADay
constructor
A new instance of ThirdOfADay.
-
#to_hash ⇒ Hash
Convert the bitmask representing a third of a day with a Hash.
Constructor Details
#initialize(bit) ⇒ ThirdOfADay
Returns a new instance of ThirdOfADay.
10 11 12 |
# File 'lib/foscam/schedule/third_of_a_day.rb', line 10 def initialize(bit) self.bit = bit end |
Instance Attribute Details
#bit ⇒ Object
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
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_hash ⇒ Hash
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
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 |