Class: Gamefic::Query::Scoped
Overview
A Scoped query uses a Scope to select entities to filter based on their relationship to the entity performing the query. For example, Scope::Children would filter from an array of the entity’s descendants.
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Attributes inherited from Base
Instance Method Summary collapse
- #ambiguous? ⇒ Boolean
-
#initialize(scope, *arguments, ambiguous: false) ⇒ Scoped
constructor
A new instance of Scoped.
- #precision ⇒ Object
- #query(subject, token) ⇒ Result
Constructor Details
#initialize(scope, *arguments, ambiguous: false) ⇒ Scoped
Returns a new instance of Scoped.
14 15 16 17 |
# File 'lib/gamefic/query/scoped.rb', line 14 def initialize scope, *arguments, ambiguous: false super(*arguments, ambiguous: ambiguous) @scope = scope end |
Instance Attribute Details
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
11 12 13 |
# File 'lib/gamefic/query/scoped.rb', line 11 def scope @scope end |
Instance Method Details
#ambiguous? ⇒ Boolean
36 37 38 |
# File 'lib/gamefic/query/scoped.rb', line 36 def ambiguous? @ambiguous end |
#precision ⇒ Object
32 33 34 |
# File 'lib/gamefic/query/scoped.rb', line 32 def precision @precision ||= @scope.precision + calculate_precision end |
#query(subject, token) ⇒ Result
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gamefic/query/scoped.rb', line 20 def query(subject, token) available = @scope.matches(subject) .that_are(*@arguments) return Result.new(token, nil) if available.include?(token) scan = Scanner.scan(available, token) return ambiguous_result(scan) if ambiguous? unambiguous_result(scan) end |