Sha256: 46ca0034fedbf0eef3b630cd24d728b07687778b5c28a9aa6c65a5f46df043fc

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 KB

Contents

module FortyFacets
  class RangeFilterDefinition < FilterDefinition
    class RangeFilter < Filter
      def build_scope
        return Proc.new { |base| base } if empty?

        Proc.new do |base|
          base.joins(definition.joins)
            .where("#{definition.qualified_column_name} >= ? AND #{definition.qualified_column_name} <= ? ", min_value, max_value ) 
        end
      end

      def min_value
        return nil if empty?
        value.split(' - ').first
      end

      def max_value
        return nil if empty?
        value.split(' - ').last
      end

      def absolute_interval
        @abosultes ||= without.result.reorder('').select("min(#{definition.qualified_column_name}) AS min, max(#{definition.qualified_column_name}) as max").first
      end

      def absolute_min
        absolute_interval.min
      end

      def absolute_max
        absolute_interval.max
      end

    end

    def build_filter(search_instance, value)
      RangeFilter.new(self, search_instance, value)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
forty_facets-0.1.9.1 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.9.0 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.8.9 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.8 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.7 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.6 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.5 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.4 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.3 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.2 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.1 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.1.0 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.0.14 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.0.13 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.0.12 lib/forty_facets/filter/range_filter_definition.rb
forty_facets-0.0.11 lib/forty_facets/filter/range_filter_definition.rb