Sha256: 42ce186db98e1a6221e42daf014cf46888f1b58d117ab213b041d77e11c91b73

Contents?: true

Size: 1.13 KB

Versions: 15

Compression:

Stored size: 1.13 KB

Contents

module ReportsKit
  module Reports
    module FilterTypes
      class String < Base
        DEFAULT_CRITERIA = {
          operator: 'contains'
        }

        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

        def valid?
          value.present?
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
reports_kit-0.7.1 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.7.0 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.5.0 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.4.1 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.4.0 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.3.3 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.3.2 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.3.1 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.3.0 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.2.0 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.1.0 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.0.4 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.0.3 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.0.2 lib/reports_kit/reports/filter_types/string.rb
reports_kit-0.0.1 lib/reports_kit/reports/filter_types/string.rb