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

#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.

Parameters:

  • possible_key (Symbol)

    possible method or key in the hash or entity.

Returns:

  • (Class)

    depending on the given results in the data.



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) : MultiEntity.new(entity_value)
  else
    super
  end
end

Instance Method Details

#confidenceFloat

Returns the confidence of the message results.

Returns:

  • (Float)

    confidence in the message for the intent.



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.

Returns:

  • (Array)

    names of each entity



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.

Returns:

  • (String)

    intent name that this message corrsponded to.



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

def intent
  outcome["intent"]
end