Class: Katalyst::Tables::Collection::Query::Parser

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/katalyst/tables/collection/query/parser.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#collectionObject (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

#queryObject

query [StringScanner]



9
10
11
# File 'app/models/concerns/katalyst/tables/collection/query/parser.rb', line 9

def query
  @query
end

#taggedObject (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

#untaggedObject (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

Parameters:

  • query (String)


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