aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormms <git@sapka.me>2024-11-08 22:27:44 +0100
committermms <git@sapka.me>2024-11-08 22:27:44 +0100
commitd82a6d1311ad72dc5a534b982f210f7180cdaeb1 (patch)
treeb5fbde06eeea78e798748af02d031146153d3fb4 /lib
parenteb09313a38aecf7e7cc5292a2fd1c7845609ff1c (diff)
fix: parens in filters
Diffstat (limited to 'lib')
-rw-r--r--lib/some/messages.rb17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/some/messages.rb b/lib/some/messages.rb
index 264fac6..5e2ff48 100644
--- a/lib/some/messages.rb
+++ b/lib/some/messages.rb
@@ -7,30 +7,29 @@ module Some
OR_CONJUCTION = :or
DEFAULT_CONJUCTION = AND_CONJUCTION
- Token = Struct.new(:id, :conjuction, :field, :value) do
+ Token = Struct.new(:conjuction, :field, :value, :messages) do
def to_query
- conjuction_to_use = id > 1 ? conjuction : ''
+ conjuction_to_use = messages.next_token_id > 1 ? conjuction : ''
return "#{conjuction_to_use} (#{value})" if field == :direct
"#{conjuction_to_use} (#{field}:#{value})"
end
end
- TokenGroup = Struct.new(:conjuction, :tokens) do
+ TokenGroup = Struct.new(:conjuction, :tokens, :messages) do
def initialize(*)
super
- @token_count = 0
end
def to_query
- "(#{tokens.flat_map(&:to_query).join(' ')})"
+ tokens.flat_map(&:to_query).join(' ').to_s
end
def push_token(field, value)
if value.is_a? String
- tokens.push(Token.new(next_token_id, conjuction, field, value))
+ tokens.push(Token.new(conjuction, field, value, messages))
elsif value.is_a? Array
- group = TokenGroup.new(OR_CONJUCTION, [])
+ group = TokenGroup.new(OR_CONJUCTION, [], messages)
value.each do |val|
group.push_token(field, val)
end
@@ -74,11 +73,11 @@ module Some
end
def add_filter_from_string(string)
- @query << Token.new(next_token_id, current_conjuction, :direct, string)
+ @query << Token.new(current_conjuction, :direct, string, self)
end
def add_filter_from_hash(hash)
- group = TokenGroup.new(AND_CONJUCTION, [])
+ group = TokenGroup.new(current_conjuction, [], self)
hash.each do |key, value|
group.push_token(key, value)
end