Skip to content

Commit 020310c

Browse files
feat(filter): add "is in" filter (#518)
1 parent f2c8153 commit 020310c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/services/forest_liana/filters_parser.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,20 @@ def parse_operator(operator)
149149

150150
def parse_value(operator, value)
151151
case operator
152-
when 'not', 'greater_than', 'less_than', 'not_equal', 'equal', 'before', 'after', 'in'
152+
when 'not', 'greater_than', 'less_than', 'not_equal', 'equal', 'before', 'after'
153153
value
154154
when 'contains', 'not_contains'
155155
"%#{value}%"
156156
when 'starts_with'
157157
"#{value}%"
158158
when 'ends_with'
159159
"%#{value}"
160+
when 'in'
161+
if value.kind_of?(String)
162+
value.split(',').map { |val| val.strip() }
163+
else
164+
value
165+
end
160166
when 'present', 'blank'
161167
else
162168
raise_unknown_operator_error(operator)

spec/services/forest_liana/filters_parser_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ module ForestLiana
396396
it { expect(filter_parser.parse_value('present', nil)).to eq nil }
397397
it { expect(filter_parser.parse_value('equal', 'yes')).to eq 'yes' }
398398
it { expect(filter_parser.parse_value('blank', nil)).to eq nil }
399+
it { expect(filter_parser.parse_value('in', 'yes,maybe ,no ')).to eq ['yes', 'maybe', 'no'] }
400+
it { expect(filter_parser.parse_value('in', 123)).to eq 123 }
399401
end
400402

401403
context 'on unknown operator' do

0 commit comments

Comments
 (0)