Class: Gamefic::Command
- Inherits:
-
Object
- Object
- Gamefic::Command
- Defined in:
- lib/gamefic/command.rb
Overview
A concrete representation of an input as a verb and an array of arguments.
Instance Attribute Summary collapse
- #arguments ⇒ Array<Array<Entity>, Entity, String> readonly
- #precision ⇒ Integer readonly
- #strictness ⇒ Integer readonly
- #verb ⇒ Symbol readonly
Class Method Summary collapse
-
.compose(actor, input) ⇒ Command
Compose a command from input.
Instance Method Summary collapse
-
#initialize(verb, arguments, strictness = 0, precision = 0) ⇒ Command
constructor
A new instance of Command.
- #inspect ⇒ Object
- #substantiality ⇒ Object
Constructor Details
#initialize(verb, arguments, strictness = 0, precision = 0) ⇒ Command
TODO:
Consider making strictness and precision required or providing another generator
Returns a new instance of Command.
26 27 28 29 30 31 |
# File 'lib/gamefic/command.rb', line 26 def initialize verb, arguments, strictness = 0, precision = 0 @verb = verb @arguments = arguments @strictness = strictness @precision = precision end |
Instance Attribute Details
#arguments ⇒ Array<Array<Entity>, Entity, String> (readonly)
11 12 13 |
# File 'lib/gamefic/command.rb', line 11 def arguments @arguments end |
#precision ⇒ Integer (readonly)
17 18 19 |
# File 'lib/gamefic/command.rb', line 17 def precision @precision end |
#strictness ⇒ Integer (readonly)
14 15 16 |
# File 'lib/gamefic/command.rb', line 14 def strictness @strictness end |
#verb ⇒ Symbol (readonly)
8 9 10 |
# File 'lib/gamefic/command.rb', line 8 def verb @verb end |
Class Method Details
.compose(actor, input) ⇒ Command
Compose a command from input.
47 48 49 50 51 |
# File 'lib/gamefic/command.rb', line 47 def compose actor, input expressions = Syntax.tokenize(input, actor.epic.syntaxes) expressions.flat_map { |expression| expression_to_commands(actor, expression) } .first || Command.new(nil, []) end |
Instance Method Details
#inspect ⇒ Object
37 38 39 |
# File 'lib/gamefic/command.rb', line 37 def inspect "#<#{self.class} #{([verb] + arguments).map(&:inspect).join(', ')}>" end |
#substantiality ⇒ Object
33 34 35 |
# File 'lib/gamefic/command.rb', line 33 def substantiality @substantiality ||= arguments.that_are(Entity).length + (verb ? 1 : 0) end |