Class: Gamefic::Query::General
- Defined in:
- lib/gamefic/query/general.rb
Overview
A General query accepts an array of entities to filter. Unlike Scoped queries, the resulting entities will not necessarily be in the actor’s immediate vicinity.
General queries can also be passed a Proc that returns an array of entities. If the Proc accepts an argument, it will be given the subject of the query.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(entities, *arguments, ambiguous: false) ⇒ General
constructor
A new instance of General.
- #query(subject, token) ⇒ Object
- #select(subject) ⇒ Object
Methods inherited from Base
#accept?, #ambiguous?, #precision
Constructor Details
#initialize(entities, *arguments, ambiguous: false) ⇒ General
Returns a new instance of General.
17 18 19 20 |
# File 'lib/gamefic/query/general.rb', line 17 def initialize entities, *arguments, ambiguous: false super(*arguments, ambiguous: ambiguous) @entities = entities end |
Instance Method Details
#query(subject, token) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/gamefic/query/general.rb', line 26 def query subject, token filtered = available_entities(subject).that_are(*@arguments) return Result.new(token, nil) if filtered.include?(token) scan = Scanner.scan(filtered, token) ambiguous? ? ambiguous_result(scan) : unambiguous_result(scan) end |
#select(subject) ⇒ Object
22 23 24 |
# File 'lib/gamefic/query/general.rb', line 22 def select subject available_entities(subject).that_are(*@arguments) end |