class Searchmatcher

Attributes

field[RW]
klass[RW]
value[RW]

Public Class Methods

new(klass, options) click to toggle source
# File lib/searchmatcher.rb, line 2
def initialize(klass, options)
  @field = options.keys.first.to_s
  @value = options.values.first
  @klass = klass
end

Public Instance Methods

formater() click to toggle source
# File lib/searchmatcher.rb, line 12
def formater
  return {} if field.nil? || field.blank?
  field.split("_or_").map { |f| f  + " LIKE :search" }.join(" OR ")
end
results() click to toggle source
# File lib/searchmatcher.rb, line 8
def results
   klass.where(formater, search: "#{value}%")
end