Class: Inflect::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/inflect/request.rb

Overview

Class that parses the incoming data and builds the semantics around the request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(words) ⇒ Request

The request is built from an array of words. Depending on the size the arguments and the action are built in a different ways.

Examples:

%W[WEATHER] -> {service_key: weather, action: 'default'}
%W[WEATHER TODAY] -> {service_key: weather, action: 'today'}
%W[WEATHER TODAY BUENOS\ AIRES] -> {service_key: weather, action: 'today',
args: ['Buenos Aires']}


15
16
17
18
19
20
# File 'lib/inflect/request.rb', line 15

def initialize(words)
  @query_words = words.dup
  @keyword = words.shift
  @action = words.first.nil? ? :default : words.shift.downcase.to_sym
  @arguments = words.map(&:downcase)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/inflect/request.rb', line 5

def action
  @action
end

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/inflect/request.rb', line 5

def arguments
  @arguments
end

#keywordObject (readonly)

Returns the value of attribute keyword.



5
6
7
# File 'lib/inflect/request.rb', line 5

def keyword
  @keyword
end

#query_wordsObject (readonly)

Returns the value of attribute query_words.



5
6
7
# File 'lib/inflect/request.rb', line 5

def query_words
  @query_words
end