class Gamefic::Action


The handler for executing a command response.

def self.sort(actions)

Returns:
  • (Array) -

Parameters:
  • actions (Array) --
def self.sort(actions)
  actions.sort_by.with_index do |action, idx|
    [-action.substantiality, -action.strictness, -action.precision, idx]
  end
end

def arguments

def arguments
  matches.map(&:argument)
end

def command

def command
  @command ||= Command.new(response.verb, matches.map(&:argument), response.meta?, input)
end

def execute

def execute
  response.execute(actor, *arguments)
  self
end

def initialize(actor, response, matches, input = nil)

Parameters:
  • input (String, nil) --
  • matches (Array) --
  • response (Response) --
  • actor (Actor) --
def initialize(actor, response, matches, input = nil)
  @actor = actor
  @response = response
  @matches = matches
  @input = input
end

def invalid?

def invalid?
  !valid?
end

def meta?

def meta?
  response.meta?
end

def precision

Returns:
  • (Integer) -
def precision
  response.precision
end

def queries

def queries
  response.queries
end

def strictness

Returns:
  • (Integer) -
def strictness
  matches.sum(0, &:strictness)
end

def substantiality


arguments are concrete entities and whether the action has a verb.
The total substantiality of the action, based on how many of the
def substantiality
  arguments.that_are(Entity).length + (verb ? 1 : 0)
end

def valid?

def valid?
  response.accept?(actor, command)
end

def verb

def verb
  response.verb
end