Class: GoogleAssistant::DialogState
- Inherits:
-
Object
- Object
- GoogleAssistant::DialogState
- Defined in:
- lib/google_assistant/dialog_state.rb
Constant Summary collapse
- DEFAULT_STATE =
{ "state" => nil, "data" => {} }.freeze
Instance Method Summary collapse
- #data ⇒ Object
- #data=(data) ⇒ Object
-
#initialize(state_hash_or_conversation_token = nil) ⇒ DialogState
constructor
A new instance of DialogState.
- #state ⇒ Object
- #state=(state) ⇒ Object
- #to_json ⇒ Object
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
#data ⇒ Object
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 |
#state ⇒ Object
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_json ⇒ Object
38 39 40 |
# File 'lib/google_assistant/dialog_state.rb', line 38 def to_json state_hash.to_json end |