Class: Wit::REST::Intent

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

Overview

Intent wrapper for intent specific results

Instance Method Summary collapse

Methods inherited from Result

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

Constructor Details

#initialize(resultData, requestRest = nil, requestPath = nil, requestBody = nil) ⇒ Wit::REST::Expression

Performs additional instance variable generation for expressions.

Parameters:

  • resultData (Hash)

    data from the call.

  • requestRest (String) (defaults to: nil)

    rest code for the call.

  • requestPath (String) (defaults to: nil)

    request path for the call.

  • requestBody (Hash) (defaults to: nil)

    body of the call.



17
18
19
20
21
22
# File 'lib/wit_ruby/rest/intent.rb', line 17

def initialize(resultData, requestRest=nil, requestPath=nil, requestBody=nil)
  super
  @expressions = @rawdata["expressions"].map do |expression_hash|
    Expression.new(expression_hash)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Wit::REST::Result

Instance Method Details

#entities_usedArray

Return entities used with there id as an array of strings.

Returns:

  • (Array)

    entity names that are used in this intent.



45
46
47
48
49
50
51
# File 'lib/wit_ruby/rest/intent.rb', line 45

def entities_used
  entities_arr = Array.new
  @entities.each do |entity|
    entities_arr << entity.id unless entities_arr.include?(entity.id)
  end
  return entities_arr
end

#expression_bodiesArray

Return the expression bodies as an array of strings.

Returns:

  • (Array)

    body of each expression.



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

def expression_bodies
  expression_bodies_arr = Array.new
  @expressions.each do |expression|
    expression_bodies_arr << expression.body
  end
  return expression_bodies_arr
end

#expressionsArray

Return the list of expressions as array of expression objects

Returns:

  • (Array)

    expressions in this intent.



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

def expressions
  return @expressions
end