Sha256: de9544f6a5e8663f5c3af6fbc77417178b46f36efdd4e392a07109bb1ad97f2d

Contents?: true

Size: 817 Bytes

Versions: 9

Compression:

Stored size: 817 Bytes

Contents

module ReportsKit
  module Reports
    module FilterTypes
      class Number < Base
        DEFAULT_CRITERIA = {}

        def apply_conditions(records)
          case criteria[:operator]
          when '>'
            records.where(column => (value.to_i...Float::INFINITY))
          when '>='
            records.where(column => (value.to_i..Float::INFINITY))
          when '<'
            records.where(column => (-Float::INFINITY...value.to_i))
          when '<='
            records.where(column => (-Float::INFINITY..value.to_i))
          when '='
            records.where(column => value.to_i)
          else
            raise ArgumentError.new("Unsupported operator: '#{criteria[:operator]}'")
          end
        end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
reports_kit-0.7.1 lib/reports_kit/reports/filter_types/number.rb
reports_kit-0.7.0 lib/reports_kit/reports/filter_types/number.rb
reports_kit-0.5.0 lib/reports_kit/reports/filter_types/number.rb
reports_kit-0.4.1 lib/reports_kit/reports/filter_types/number.rb
reports_kit-0.4.0 lib/reports_kit/reports/filter_types/number.rb
reports_kit-0.3.3 lib/reports_kit/reports/filter_types/number.rb
reports_kit-0.3.2 lib/reports_kit/reports/filter_types/number.rb
reports_kit-0.3.1 lib/reports_kit/reports/filter_types/number.rb
reports_kit-0.3.0 lib/reports_kit/reports/filter_types/number.rb