Class: Katalyst::Tables::Collection::Query::ArrayValueParser

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

Defined Under Namespace

Classes: Value

Instance Attribute Summary

Attributes inherited from ValueParser

#key, #query

Instance Method Summary collapse

Methods inherited from ValueParser

#literal?, #range, #skip_whitespace, #tagged?, #take_quoted_value, #take_unquoted_value

Constructor Details

#initializeArrayValueParser

Returns a new instance of ArrayValueParser.



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

def initialize(...)
  super

  @value = []
end

Instance Method Details

#parse(query) ⇒ Object

Parameters:

  • query (StringScanner)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/concerns/katalyst/tables/collection/query/array_value_parser.rb', line 15

def parse(query)
  @query = query

  query.scan(/#{'\['}\s*/)

  until query.eos?
    @value_start = query.charpos
    break unless take_quoted_value || take_unquoted_value
    break unless take_delimiter
  end

  query.scan(/\s*#{'\]'}?/)

  @end = query.charpos

  self
end

#take_delimiterObject



33
34
35
# File 'app/models/concerns/katalyst/tables/collection/query/array_value_parser.rb', line 33

def take_delimiter
  query.scan(/\s*#{','}\s*/)
end

#valueObject



37
38
39
# File 'app/models/concerns/katalyst/tables/collection/query/array_value_parser.rb', line 37

def value
  @value.map(&:value)
end

#value=(value) ⇒ Object



41
42
43
# File 'app/models/concerns/katalyst/tables/collection/query/array_value_parser.rb', line 41

def value=(value)
  @value << Value.new(value, @value_start, @query.charpos)
end

#value_at(position) ⇒ Object



45
46
47
# File 'app/models/concerns/katalyst/tables/collection/query/array_value_parser.rb', line 45

def value_at(position)
  @value.detect { |v| v.range.cover?(position) }&.value
end