Module: Rooftop::Rails::Extras::ResourceSearch

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/rooftop/rails/extras/resource_search.rb

Overview

A module to search for free text in a resource. You can add extra fields to search the free text in, by specifying a proc to call (which should return the text you want to search)

Instance Method Summary collapse

Instance Method Details

#searchable_textObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/concerns/rooftop/rails/extras/resource_search.rb', line 30

def searchable_text
  remove_regex = /[^a-zA-z1-9 ]/
  text = []
  text << title.gsub(remove_regex,"").downcase
  text << ActionController::Base.helpers.strip_tags(fields.content).gsub(remove_regex,"").downcase
  # Iterate over the search field lambdas, and call each one, passing in self. Check the arity is 1, to ensure that the lambda is expecting the object
  self.class.search_fields.each do |field|
    if field.arity == 1
      text << ActionController::Base.helpers.strip_tags(field.call(self)).gsub(remove_regex,"").downcase
    end
  end
  text.join(" ")

end