Module: Care::AutoFinder::FinderMethods

Extended by:
ActiveSupport::Concern
Included in:
Finder
Defined in:
lib/care/auto_finder/finder_methods.rb

Instance Method Summary collapse

Instance Method Details

#range_filter(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/care/auto_finder/finder_methods.rb', line 14

def range_filter(options)
  options = Struct.new(*options.keys).new(*options.values)

  if options.start.present? && options.end.present?
    options.collection.where(options.column => options.start..options.end)
  elsif options.start.present?
    options.collection.where("#{options.column} >= ?", options.start)
  elsif options.end.present?
    options.collection.where("#{options.column} <= ?", options.end)
  else
    options.collection
  end
end