Class: Katalyst::Tables::Collection::Query::Parser
- Inherits:
-
Object
- Object
- Katalyst::Tables::Collection::Query::Parser
- Defined in:
- app/models/concerns/katalyst/tables/collection/query/parser.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#query ⇒ Object
query [StringScanner].
-
#tagged ⇒ Object
readonly
Returns the value of attribute tagged.
-
#untagged ⇒ Object
readonly
Returns the value of attribute untagged.
Instance Method Summary collapse
-
#initialize(collection) ⇒ Parser
constructor
A new instance of Parser.
- #parse(query) ⇒ Object
- #token_at_position(position:) ⇒ Object
Constructor Details
#initialize(collection) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 16 |
# File 'app/models/concerns/katalyst/tables/collection/query/parser.rb', line 12 def initialize(collection) @collection = collection @tagged = {} @untagged = [] end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
10 11 12 |
# File 'app/models/concerns/katalyst/tables/collection/query/parser.rb', line 10 def collection @collection end |
#query ⇒ Object
query [StringScanner]
9 10 11 |
# File 'app/models/concerns/katalyst/tables/collection/query/parser.rb', line 9 def query @query end |
#tagged ⇒ Object (readonly)
Returns the value of attribute tagged.
10 11 12 |
# File 'app/models/concerns/katalyst/tables/collection/query/parser.rb', line 10 def tagged @tagged end |
#untagged ⇒ Object (readonly)
Returns the value of attribute untagged.
10 11 12 |
# File 'app/models/concerns/katalyst/tables/collection/query/parser.rb', line 10 def untagged @untagged end |
Instance Method Details
#parse(query) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/concerns/katalyst/tables/collection/query/parser.rb', line 19 def parse(query) @query = StringScanner.new(query) until @query.eos? skip_whitespace # break to ensure we don't loop indefinitely on bad input break unless take_tagged || take_untagged end self end |
#token_at_position(position:) ⇒ Object
32 33 34 35 |
# File 'app/models/concerns/katalyst/tables/collection/query/parser.rb', line 32 def token_at_position(position:) tagged.values.detect { |v| v.range.cover?(position) } || untagged.detect { |v| v.range.cover?(position) } end |