Class: Card::FilterCql
- Inherits:
-
Object
- Object
- Card::FilterCql
- Defined in:
- lib/card/filter_cql.rb
Overview
Class for generating CQL based on filter params
Instance Method Summary collapse
- #add_rule(key, value) ⇒ Object
- #add_to_cql(key, value) ⇒ Object
-
#initialize(filter_keys_with_values, extra_cql = {}) ⇒ FilterCql
constructor
A new instance of FilterCql.
- #to_cql ⇒ Object
Constructor Details
#initialize(filter_keys_with_values, extra_cql = {}) ⇒ FilterCql
Returns a new instance of FilterCql.
4 5 6 7 8 9 10 11 |
# File 'lib/card/filter_cql.rb', line 4 def initialize filter_keys_with_values, extra_cql={} @filter_cql = Hash.new { |h, k| h[k] = [] } @rules = yield if block_given? @rules ||= {} @filter_keys_with_values = filter_keys_with_values @extra_cql = extra_cql prepare_filter_cql end |
Instance Method Details
#add_rule(key, value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/card/filter_cql.rb', line 17 def add_rule key, value return unless value.present? case @rules[key] when Symbol send("#{@rules[key]}_rule", key, value) when Proc @rules[key].call(key, value).each do |cql_key, val| @filter_cql[cql_key] << val end else send "#{key}_cql", value end end |
#add_to_cql(key, value) ⇒ Object
13 14 15 |
# File 'lib/card/filter_cql.rb', line 13 def add_to_cql key, value @filter_cql[key] << value end |
#to_cql ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/card/filter_cql.rb', line 32 def to_cql @cql = {} @filter_cql.each do |cql_key, values| next if values.empty? case cql_key when :right_plus, :left_plus, :type merge_using_and cql_key, values else merge_using_array cql_key, values end end @cql.merge @extra_cql end |