Class: Ban::RcEvent
Constant Summary collapse
- CMD =
0x35
Instance Attribute Summary collapse
-
#bits ⇒ Object
readonly
Returns the value of attribute bits.
-
#decimal ⇒ Object
readonly
Returns the value of attribute decimal.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Class Method Summary collapse
Instance Method Summary collapse
- #binary ⇒ Object
-
#initialize(decimal, bits, delay, protocol) ⇒ RcEvent
constructor
A new instance of RcEvent.
- #name ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #tristate ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(decimal, bits, delay, protocol) ⇒ RcEvent
Returns a new instance of RcEvent.
11 12 13 |
# File 'lib/ban/events/rc_event.rb', line 11 def initialize(decimal, bits, delay, protocol) @decimal, @bits, @delay, @protocol = decimal, bits, delay, protocol end |
Instance Attribute Details
#bits ⇒ Object (readonly)
Returns the value of attribute bits.
5 6 7 |
# File 'lib/ban/events/rc_event.rb', line 5 def bits @bits end |
#decimal ⇒ Object (readonly)
Returns the value of attribute decimal.
5 6 7 |
# File 'lib/ban/events/rc_event.rb', line 5 def decimal @decimal end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
5 6 7 |
# File 'lib/ban/events/rc_event.rb', line 5 def delay @delay end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
5 6 7 |
# File 'lib/ban/events/rc_event.rb', line 5 def protocol @protocol end |
Class Method Details
.parse(data) ⇒ Object
7 8 9 |
# File 'lib/ban/events/rc_event.rb', line 7 def self.parse(data) new(*Ban.decode7bit(data).split('|').map(&:to_i)) end |
Instance Method Details
#binary ⇒ Object
43 44 45 |
# File 'lib/ban/events/rc_event.rb', line 43 def binary ("%#{bits}s" % decimal.to_s(2)).gsub(' ', '0') end |
#name ⇒ Object
15 16 17 |
# File 'lib/ban/events/rc_event.rb', line 15 def name (tristate[-1] == 'F') ? 'rc-turned-on' : 'rc-turned-off' end |
#to_hash ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ban/events/rc_event.rb', line 26 def to_hash { 'decimal' => decimal, 'bits' => bits, 'binary' => binary, 'tristate' => tristate, 'delay' => delay, 'protocol' => protocol } end |
#to_s ⇒ Object
37 38 39 40 41 |
# File 'lib/ban/events/rc_event.rb', line 37 def to_s "decimal: #{decimal} (#{bits} bits) binary #{binary} " + "tri-state: #{tristate} pulse length: #{delay} (ms) " + "protocol: #{protocol}" end |
#tristate ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ban/events/rc_event.rb', line 47 def tristate binary.gsub(/[0-9]{2}/) do |match| if match == '00' '0' elsif match == '01' 'F' else raise ArgumentError, "#{match} not applicable" end end end |
#valid? ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/ban/events/rc_event.rb', line 19 def valid? tristate true rescue ArgumentError false end |