Class: Wit::REST::Message

Inherits:
Result
  • Object
show all
Defined in:
lib/wit_ruby/rest/message.rb

Overview

Message wrapper for message specific results.

Instance Method Summary collapse

Methods inherited from Result

#empty?, #entities, #initialize, #raw_data, #refreshable?, #restBody, #restCode, #restPath

Constructor Details

This class inherits a constructor from Wit::REST::Result

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(possible_key, *args, &block) ⇒ Class

Checks if the method is one of the keys in the hash. Overides the one in Wit::REST::Result as it might correspond to a given entity. If it is then we can return the given value. If not, then go to method_missing in Wit::REST::Result.



42
43
44
45
46
47
48
49
# File 'lib/wit_ruby/rest/message.rb', line 42

def method_missing(possible_key, *args, &block)
  if @rawdata["outcome"]["entities"].has_key?(possible_key.to_s)
    entity_value = @rawdata["outcome"]["entities"][possible_key.to_s]
    entity_value.class == Hash ? Entity.new(entity_value) : EntityArray.new(entity_value)
  else
    super
  end
end

Instance Method Details

#confidenceFloat

Returns the confidence of the message results.



13
14
15
# File 'lib/wit_ruby/rest/message.rb', line 13

def confidence
  outcome["confidence"]
end

#entity_namesArray

Generates Array of the names of each entity in this message.



27
28
29
30
31
32
33
# File 'lib/wit_ruby/rest/message.rb', line 27

def entity_names
  entity_arr = Array.new
  outcome["entities"].each_key do |key|
    entity_arr << key
  end
  return entity_arr
end

#intentString

Returns the intent that this message corresponded to.



20
21
22
# File 'lib/wit_ruby/rest/message.rb', line 20

def intent
  outcome["intent"]
end