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



49
50
51
52
53
54
55
56
# File 'lib/wit_ruby/rest/message.rb', line 49

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

Instance Method Details

#confidence(index = 0) ⇒ Float

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(index=0)
  self.raw_data["outcomes"][index]["confidence"]
end

#entities(index = 0) ⇒ Object

Returns the entities that this message corresponded to.

Returns:

  • Hash of entities that this message corrsponded to.



27
28
29
# File 'lib/wit_ruby/rest/message.rb', line 27

def entities(index=0)
  self.raw_data["outcomes"][index]["entities"]
end

#entity_names(index = 0) ⇒ Array

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

Returns:

  • (Array)

    names of each entity



34
35
36
37
38
39
40
# File 'lib/wit_ruby/rest/message.rb', line 34

def entity_names(index=0)
  entity_arr = Array.new
  self.raw_data["outcomes"][index]["entities"].each_key do |key|
    entity_arr << key
  end
  return entity_arr
end

#intent(index = 0) ⇒ String

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(index=0)
  self.raw_data["outcomes"][index]["intent"]
end