Class: Wizrb::Shared::State

Inherits:
Object
  • Object
show all
Defined in:
lib/wizrb/shared/state.rb

Direct Known Subclasses

Lighting::State

Constant Summary collapse

STATE_KEYS =
%i[state].freeze

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



8
9
10
# File 'lib/wizrb/shared/state.rb', line 8

def initialize
  @state = {state: false}
end

Instance Method Details

#parse!(response) ⇒ Object



12
13
14
15
16
17
# File 'lib/wizrb/shared/state.rb', line 12

def parse!(response)
  result = response&.dig("result")
  return unless result

  @state = result.transform_keys(&:to_sym).slice(*STATE_KEYS)
end

#powerObject



19
20
21
# File 'lib/wizrb/shared/state.rb', line 19

def power
  @state[:state]
end

#to_json(*_args) ⇒ Object



27
28
29
# File 'lib/wizrb/shared/state.rb', line 27

def to_json(*_args)
  @state.to_json
end

#to_sObject



23
24
25
# File 'lib/wizrb/shared/state.rb', line 23

def to_s
  @state.to_s
end