Class: GoogleAssistant::DialogState

Inherits:
Object
  • Object
show all
Defined in:
lib/google_assistant/dialog_state.rb

Constant Summary collapse

DEFAULT_STATE =
{ "state" => nil, "data" => {} }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(state_hash_or_conversation_token = nil) ⇒ DialogState

Returns a new instance of DialogState.



9
10
11
12
13
14
15
16
17
18
# File 'lib/google_assistant/dialog_state.rb', line 9

def initialize(state_hash_or_conversation_token = nil)
  if state_hash_or_conversation_token.is_a?(String)
    @raw_token = state_hash_or_conversation_token
    @state_hash = parse_token(state_hash_or_conversation_token)
  elsif state_hash_or_conversation_token.is_a?(Hash)
    @state_hash = state_hash_or_conversation_token
  else
    @state_hash = DEFAULT_STATE.dup
  end
end

Instance Method Details

#dataObject



28
29
30
# File 'lib/google_assistant/dialog_state.rb', line 28

def data
  state_hash["data"]
end

#data=(data) ⇒ Object



32
33
34
35
36
# File 'lib/google_assistant/dialog_state.rb', line 32

def data=(data)
  raise "DialogState data must be a hash" unless data.is_a?(Hash)

  state_hash["data"] = data
end

#stateObject



20
21
22
# File 'lib/google_assistant/dialog_state.rb', line 20

def state
  state_hash["state"]
end

#state=(state) ⇒ Object



24
25
26
# File 'lib/google_assistant/dialog_state.rb', line 24

def state=(state)
  state_hash["state"] = state
end

#to_jsonObject



38
39
40
# File 'lib/google_assistant/dialog_state.rb', line 38

def to_json
  state_hash.to_json
end