Class: RShade::Filter::FilterBuilder
- Defined in:
- lib/rshade/filter/filter_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.build(arr) ⇒ Object
4 5 6 |
# File 'lib/rshade/filter/filter_builder.rb', line 4 def self.build(arr) new.traverse(arr) end |
Instance Method Details
#map ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/rshade/filter/filter_builder.rb', line 8 def map { or: [RShade::Filter::FilterComposition::OR_OP, 2], and: [RShade::Filter::FilterComposition::AND_OP, 2], unary: [RShade::Filter::FilterComposition::UNARY_OP, 1] } end |
#traverse(arr) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rshade/filter/filter_builder.rb', line 16 def traverse(arr) op, arity = map[arr[0]] arg1 = arr[1] arg2 = nil arg2 = arr[2] if arity == 2 arg1 = traverse(arg1) if arg1.is_a?(Array) arg2 = traverse(arg2) if arg2.is_a?(Array) RShade::Filter::FilterComposition.new(op, arg1, arg2) end |