Class: ReportsKit::Reports::FilterTypes::String

Inherits:
Base
  • Object
show all
Defined in:
lib/reports_kit/reports/filter_types/string.rb

Constant Summary collapse

DEFAULT_CRITERIA =
{
  operator: 'contains'
}

Instance Attribute Summary

Attributes inherited from Base

#primary_dimension, #properties, #settings

Instance Method Summary collapse

Methods inherited from Base

#apply_filter, #default_criteria, #initialize

Constructor Details

This class inherits a constructor from ReportsKit::Reports::FilterTypes::Base

Instance Method Details

#apply_conditions(records) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/reports_kit/reports/filter_types/string.rb', line 9

def apply_conditions(records)
  case criteria[:operator]
  when 'equals'
    records.where("#{column} = ?", value)
  when 'contains'
    records.where("#{column} ILIKE ?", "%#{value}%")
  when 'starts_with'
    records.where("#{column} ILIKE ?", "#{value}%")
  when 'ends_with'
    records.where("#{column} ILIKE ?", "%#{value}")
  when 'does_not_equal'
    records.where("#{column} != ?", value)
  when 'does_not_contain'
    records.where("#{column} NOT ILIKE ?", "%#{value}%")
  when 'does_not_start_with'
    records.where("#{column} NOT ILIKE ?", "#{value}%")
  when 'does_not_end_with'
    records.where("#{column} NOT ILIKE ?", "%#{value}")
  else
    raise ArgumentError.new("Unsupported operator: '#{criteria[:operator]}'")
  end
end

#valid?Boolean

Returns:



32
33
34
# File 'lib/reports_kit/reports/filter_types/string.rb', line 32

def valid?
  value.present?
end