class GoogleAssistant::DialogState
Constants
- DEFAULT_STATE
Attributes
raw_token[R]
state_hash[R]
Public Class Methods
new(state_hash_or_conversation_token = nil)
click to toggle source
# 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
Public Instance Methods
data()
click to toggle source
# File lib/google_assistant/dialog_state.rb, line 28 def data state_hash["data"] end
data=(data)
click to toggle source
# 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()
click to toggle source
# File lib/google_assistant/dialog_state.rb, line 20 def state state_hash["state"] end
state=(state)
click to toggle source
# File lib/google_assistant/dialog_state.rb, line 24 def state=(state) state_hash["state"] = state end
to_json()
click to toggle source
# File lib/google_assistant/dialog_state.rb, line 38 def to_json state_hash.to_json end
Private Instance Methods
parse_token(token)
click to toggle source
# File lib/google_assistant/dialog_state.rb, line 46 def parse_token(token) JSON.parse(token) rescue JSON::ParserError, TypeError DEFAULT_STATE.dup end