Class: QueryReport::FilterModule::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/query_report/filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, column, options, &block) ⇒ Filter

Initializes filter with the proper parameters

Parameters:

  • params (Hash)

    The params from the http request

  • column (Symbol)

    the name of the filter or the column name for the filter to be applied on

  • block

    The block is passed for a manual query, The first param the block will receive is the query chain, and the rest is the values for that particular filter.

See Also:



62
63
64
65
66
# File 'lib/query_report/filter.rb', line 62

def initialize(params, column, options, &block)
  @params, @column, @options, @comparators, @block = params, column, options, [], block
  @type = options.kind_of?(String) ? options : options[:type]
  generate_comparators
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



55
56
57
# File 'lib/query_report/filter.rb', line 55

def block
  @block
end

#columnObject (readonly)

Returns the value of attribute column.



55
56
57
# File 'lib/query_report/filter.rb', line 55

def column
  @column
end

#comparatorsObject (readonly)

Returns the value of attribute comparators.



55
56
57
# File 'lib/query_report/filter.rb', line 55

def comparators
  @comparators
end

#optionsObject (readonly)

Returns the value of attribute options.



55
56
57
# File 'lib/query_report/filter.rb', line 55

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



55
56
57
# File 'lib/query_report/filter.rb', line 55

def params
  @params
end

#typeObject (readonly)

Returns the value of attribute type.



55
56
57
# File 'lib/query_report/filter.rb', line 55

def type
  @type
end

Class Method Details

.supported_typesObject



68
69
70
# File 'lib/query_report/filter.rb', line 68

def self.supported_types
  [:date, :datetime, :text, :boolean]
end

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/query_report/filter.rb', line 78

def custom?
  (@block || @options[:manual]) ? true : false
end

#has_default?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/query_report/filter.rb', line 86

def has_default?
  @comparators.any?(&:has_default?)
end

#params_keyObject



90
91
92
# File 'lib/query_report/filter.rb', line 90

def params_key
  custom? ? :custom_search : :q
end

#search_keysObject



82
83
84
# File 'lib/query_report/filter.rb', line 82

def search_keys
  @comparators.collect(&:search_key)
end