Module: RubySimpleSearch::ClassMethods

Defined in:
lib/ruby_simple_search.rb

Instance Method Summary collapse

Instance Method Details

#simple_search(search_term, options = {}, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_simple_search.rb', line 25

def simple_search(search_term, options = {}, &block)
  raise Errors::ATTRIBUTES_MISSING if @simple_search_attributes.blank?
  raise ArgumentError, Errors::SEARCH_ARG_TYPE unless search_term.is_a? String

  @simple_search_term             = search_term
  @simple_search_pattern          = get_pattern(options[:pattern])
  @simple_search_patterned_text   = @simple_search_pattern.gsub("q", @simple_search_term.try(:downcase))
  @simple_search_query_conditions = []
  @simple_search_query_values     = []

  build_query_conditions_and_values(options)
  extend_query(block) if block.is_a? Proc

  sql_query = [@simple_search_query_conditions.join, @simple_search_query_values]
  where(sql_query.flatten)
end