aboutsummaryrefslogtreecommitdiff
path: root/lib/some/messages.rb
blob: 2f89d2ba94927446623517193ffdc859e0944d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module Some
  class Messages
    AND_CONJUCTION = :and
    OR_CONJUCTION = :or
    DEFAULT_CONJUCTION = AND_CONJUCTION

    attr_reader :query, :current_conjuction

    def initialize
      @query = []
      @current_conjuction = AND_CONJUCTION
    end

    def or
      @current_conjuction = OR_CONJUCTION
      self
    end

    def filter(params)
      query << params.map do |key, value|
        unless value.is_a? Array
          [current_conjuction, key, value.to_sym] 
        else

          [current_conjuction,
           value.map { |subarg| [OR_CONJUCTION, key, subarg] }]
        end
      end

      self
    end

    def query_string

    end
  end
end