Class: Gamefic::Command
- Inherits:
-
Object
- Object
- Gamefic::Command
- Defined in:
- lib/gamefic/command.rb
Overview
A decomposition of a text-based command into its verb and arguments.
Commands are typically derived from tokenization against syntaxes.
Instance Attribute Summary collapse
- #arguments ⇒ Array<String> readonly
- #verb ⇒ Symbol readonly
Instance Method Summary collapse
-
#compare(other) ⇒ Object
Compare two syntaxes for the purpose of ordering them by relevance while dispatching.
-
#initialize(verb, arguments) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(verb, arguments) ⇒ Command
Returns a new instance of Command.
15 16 17 18 |
# File 'lib/gamefic/command.rb', line 15 def initialize verb, arguments @verb = verb @arguments = arguments end |
Instance Attribute Details
#arguments ⇒ Array<String> (readonly)
13 14 15 |
# File 'lib/gamefic/command.rb', line 13 def arguments @arguments end |
#verb ⇒ Symbol (readonly)
10 11 12 |
# File 'lib/gamefic/command.rb', line 10 def verb @verb end |
Instance Method Details
#compare(other) ⇒ Object
Compare two syntaxes for the purpose of ordering them by relevance while dispatching.
23 24 25 26 27 28 29 |
# File 'lib/gamefic/command.rb', line 23 def compare other if verb == other.verb other.arguments.compact.length <=> arguments.compact.length else (other.verb ? 1 : 0) <=> (verb ? 1 : 0) end end |