Method: Ego::Handler#handle

Defined in:
lib/ego/handler.rb

#handle(query) ⇒ false, Array

Match the given query against the condition.

Parameters:

  • query (String)

    the query to match the condition against

Returns:

  • (false)

    if condition doesn't match

  • (Array)

    parameters to pass to the action



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ego/handler.rb', line 62

def handle(query)
  return false unless (result = @condition.call(query))

  @action.parameters.each_with_object([]) do |param, arr|
    begin
      arr << result[param.pop]
    rescue IndexError
      arr << nil # Match group isn't defined.
    end
  end
end