Module: Gamefic::Scriptable::Syntaxes

Included in:
Gamefic::Scriptable, Responses
Defined in:
lib/gamefic/scriptable/syntaxes.rb

Instance Method Summary collapse

Instance Method Details

#interpret(command, translation) ⇒ Syntax

Create an alternate Syntax for a response. The command and its translation can be parameterized.

Examples:

Create a synonym for an ‘inventory` response.

interpret "catalogue", "inventory"
# The command "catalogue" will be translated to "inventory"

Create a parameterized synonym for a ‘look` response.

interpret "scrutinize :entity", "look :entity"
# The command "scrutinize chair" will be translated to "look chair"

Parameters:

  • command (String)

    The format of the original command

  • translation (String)

    The format of the translated command

Returns:

  • (Syntax)

    the Syntax object



20
21
22
23
24
25
26
27
28
29
# File 'lib/gamefic/scriptable/syntaxes.rb', line 20

def interpret(command, translation)
  parts = Syntax.split(command)
  additions = if parts.first.include?('|')
                parts.first.split('|').map { |verb| Syntax.new("#{verb} #{verb[1..].join(' ')}", translation) }
              else
                [Syntax.new(command, translation)]
              end
  syntaxes.concat additions
  additions
end

#syntaxesObject



31
32
33
# File 'lib/gamefic/scriptable/syntaxes.rb', line 31

def syntaxes
  @syntaxes ||= []
end