class Gamefic::Order
Build actions from explicit verbs and arguments.
The Active#execute
method uses Order
to bypass the parser while generating actions to be executed in the Dispatcher
.
Attributes
@return [Actor]
@return [Array<Object>]
@return [Symbol]
Public Class Methods
Source
# File lib/gamefic/order.rb, line 13 def initialize(actor, verb, arguments) @actor = actor @verb = verb @arguments = arguments end
@param actor [Actor] @param verb [Symbol] @param arguments [Array<Object>]
Public Instance Methods
Source
# File lib/gamefic/order.rb, line 20 def to_actions Action.sort( actor.narratives .responses_for(verb) .map { |response| match_arguments(response) } .compact ) end
@return [Array<Action>]
Private Instance Methods
Source
# File lib/gamefic/order.rb, line 40 def match_arguments(response) return nil if response.queries.length != arguments.length matches = response.queries.zip(arguments).each_with_object([]) do |zipped, result| query, param = zipped return nil unless query.accept?(actor, param) result.push Match.new(param, param, 1000) end Action.new(actor, response, matches, nil) end