Class: Ban::DoorEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/ban/events/door_event.rb

Constant Summary collapse

CMD =
0x37

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Event

#valid?

Constructor Details

#initialize(state) ⇒ DoorEvent

Returns a new instance of DoorEvent.



11
12
13
# File 'lib/ban/events/door_event.rb', line 11

def initialize(state)
  @state = state
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



5
6
7
# File 'lib/ban/events/door_event.rb', line 5

def state
  @state
end

Class Method Details

.parse(data) ⇒ Object



7
8
9
# File 'lib/ban/events/door_event.rb', line 7

def self.parse(data)
  new(Ban.decode7bit(data).downcase)
end

Instance Method Details

#nameObject



15
16
17
# File 'lib/ban/events/door_event.rb', line 15

def name
  open? ? 'door-opened' : 'door-closed'
end

#open?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ban/events/door_event.rb', line 23

def open?
  @state == 'open'
end

#to_hashObject



19
20
21
# File 'lib/ban/events/door_event.rb', line 19

def to_hash
  { 'state' => @state }
end

#to_sObject



27
28
29
# File 'lib/ban/events/door_event.rb', line 27

def to_s
  "door: #{open? ? 'opened' : 'closed'}"
end