Class: Gamefic::Expression
- Inherits:
-
Object
- Object
- Gamefic::Expression
- Defined in:
- lib/gamefic/expression.rb
Overview
A tokenization of an input from available syntaxes.
Instance Attribute Summary collapse
- #tokens ⇒ 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, tokens) ⇒ Expression
constructor
A new instance of Expression.
- #inspect ⇒ Object
Constructor Details
#initialize(verb, tokens) ⇒ Expression
Returns a new instance of Expression.
15 16 17 18 |
# File 'lib/gamefic/expression.rb', line 15 def initialize verb, tokens @verb = verb @tokens = tokens end |
Instance Attribute Details
#tokens ⇒ Array<String> (readonly)
11 12 13 |
# File 'lib/gamefic/expression.rb', line 11 def tokens @tokens end |
#verb ⇒ Symbol (readonly)
8 9 10 |
# File 'lib/gamefic/expression.rb', line 8 def verb @verb end |
Instance Method Details
#compare(other) ⇒ Object
Compare two syntaxes for the purpose of ordering them by relevance while dispatching.
26 27 28 29 30 31 32 |
# File 'lib/gamefic/expression.rb', line 26 def compare other if verb == other.verb other.tokens.compact.length <=> tokens.compact.length else (other.verb ? 1 : 0) <=> (verb ? 1 : 0) end end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/gamefic/expression.rb', line 20 def inspect "#<#{self.class} #{([verb] + tokens).map(&:inspect).join(', ')}>" end |