Sha256: 9ca386972c61684b9a0e0aaf3b17cbb05800b65338eac14097e1e034925ac5b0

Contents?: true

Size: 852 Bytes

Versions: 1

Compression:

Stored size: 852 Bytes

Contents

require 'ar_finder_form/attr'
module ArFinderForm
  module Attr
    class RangeAttrs < Base

      attr_accessor :min, :max
      def initialize(column, name, options)
        super(column, name, options)
        range = options[:range] || {}
        min_def = {:operator => '>='}.update(range[:min] || options[:min] || {})
        max_def = {:operator => '<='}.update(range[:max] || options[:max] || {})
        @min = Simple.new(column, min_def[:attr] || "#{name}_min", min_def)
        @max = Simple.new(column, max_def[:attr] || "#{name}_max", max_def)
      end

      def setup
        @min.setup
        @max.setup
      end

      def build(context)
        sub_context = context.new_sub_context(:connector => 'AND')
        @min.build(sub_context)
        @max.build(sub_context)
        context.merge(sub_context)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar_finder_form-0.1.0 lib/ar_finder_form/attr/range_attrs.rb