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 Params:

params

The params from the http request



69
70
71
72
73
# File 'lib/query_report/filter.rb', line 69

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.



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

def block
  @block
end

#columnObject (readonly)

Returns the value of attribute column.



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

def column
  @column
end

#comparatorsObject (readonly)

Returns the value of attribute comparators.



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

def comparators
  @comparators
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.supported_typesObject



75
76
77
# File 'lib/query_report/filter.rb', line 75

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

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


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

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

#has_default?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/query_report/filter.rb', line 93

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

#params_keyObject



97
98
99
# File 'lib/query_report/filter.rb', line 97

def params_key
  custom? ? :custom_search : :q
end

#search_keysObject



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

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