Class: Awesome::Triage
- Inherits:
-
Array
- Object
- Array
- Awesome::Triage
- Includes:
- Definitions::Bits, Definitions::Locales
- Defined in:
- lib/awesome/triage.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#locales ⇒ Object
Returns the value of attribute locales.
-
#multiple_types_as_one ⇒ Object
Returns the value of attribute multiple_types_as_one.
-
#page ⇒ Object
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
-
#text ⇒ Object
Returns the value of attribute text.
-
#types ⇒ Object
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
- #add_search(klass, locale, stopwords) ⇒ Object
- #clean_search_text ⇒ Object
- #filter_mods(klass) ⇒ Object
-
#initialize(*args) ⇒ Triage
constructor
A new instance of Triage.
-
#new_search_for_type_and_locale(klass, type, locale, stopwords) ⇒ Object
single type.
-
#new_search_for_types_and_locale(klass, types, locale, stopwords) ⇒ Object
multiple types.
Methods included from Definitions::Locales
Methods included from Definitions::Bits
Constructor Details
#initialize(*args) ⇒ Triage
Returns a new instance of Triage.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/awesome/triage.rb', line 30 def initialize(*args) super() @multiple_types_as_one = !args.first[:multiple_types_as_one].nil? ? args.first[:multiple_types_as_one] : false# Boolean: should the array of types be sent through to a single search, or iterated over to separate searches like locales? @page = args.first[:page] @per_page = args.first[:per_page] @text = args.first[:text] # a string @types = args.first[:types].respond_to?(:each) ? args.first[:types] : [args.first[:types]] # a symring, or array thereof (symring methods are in the Bits mixin) @locales = args.first[:locales].respond_to?(:each) ? args.first[:locales] : [args.first[:locales]] # a symring, or array thereof (symring methods are in the Bits mixin) @filters = args.first[:filters] # a ruby object (string, array, hash) to be used by subclasss search classes as a filter @redirect_url = nil # 1. Handle all locale modifiers, by creating a different search for each self.locales.each do |locale| puts "initializing locale: #{locale}" if self.class.verbose_locales locale = self.class.make_symring(locale) klass = self.class.get_class_for_locale(locale) # 2. if there is no matching class for the locale return nil puts "klass is nil" if Awesome::Triage.verbose && klass.nil? next if klass.nil? # 3. If there is a locale modifier, then make sure it matches the locale being searched or return nil locale_mods = self.class.valid_locale_modifiers(self.text, locale) puts "locale_mods is empty" if Awesome::Triage.verbose && locale_mods.empty? next if locale_mods.empty? self.add_search(klass, locale, self.class.stopwords_for_locale(locale)) #if we hit a search that tells us to redirect, do not continue break if self.redirect_url end self.compact! self end |
Instance Attribute Details
#filters ⇒ Object
Returns the value of attribute filters.
21 22 23 |
# File 'lib/awesome/triage.rb', line 21 def filters @filters end |
#locales ⇒ Object
Returns the value of attribute locales.
21 22 23 |
# File 'lib/awesome/triage.rb', line 21 def locales @locales end |
#multiple_types_as_one ⇒ Object
Returns the value of attribute multiple_types_as_one.
21 22 23 |
# File 'lib/awesome/triage.rb', line 21 def multiple_types_as_one @multiple_types_as_one end |
#page ⇒ Object
Returns the value of attribute page.
21 22 23 |
# File 'lib/awesome/triage.rb', line 21 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
21 22 23 |
# File 'lib/awesome/triage.rb', line 21 def per_page @per_page end |
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
21 22 23 |
# File 'lib/awesome/triage.rb', line 21 def redirect_url @redirect_url end |
#text ⇒ Object
Returns the value of attribute text.
21 22 23 |
# File 'lib/awesome/triage.rb', line 21 def text @text end |
#types ⇒ Object
Returns the value of attribute types.
21 22 23 |
# File 'lib/awesome/triage.rb', line 21 def types @types end |
Class Method Details
.clean_search_text(text) ⇒ Object
117 118 119 |
# File 'lib/awesome/triage.rb', line 117 def self.clean_search_text(text) text.gsub(self.search_locale_modifiers_regex(true), "") end |
.configure_search_locales {|@@search_locales| ... } ⇒ Object
14 15 16 |
# File 'lib/awesome/triage.rb', line 14 def self.configure_search_locales(&block) yield @@search_locales end |
Instance Method Details
#add_search(klass, locale, stopwords) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/awesome/triage.rb', line 60 def add_search(klass, locale, stopwords) # 4. Handle all type modifiers, by creating a different search for each if self.multiple_types_as_one new_search = self.new_search_for_types_and_locale(klass, self.types, locale, stopwords) self.redirect_url = new_search.redirect_url self << new_search else self.types.each do |typ| new_search = self.new_search_for_type_and_locale(klass, typ, locale, stopwords) self.redirect_url = new_search.redirect_url self << new_search end end end |
#clean_search_text ⇒ Object
112 113 114 115 |
# File 'lib/awesome/triage.rb', line 112 def clean_search_text txt = Awesome::Triage.clean_search_text(self.search_text) Awesome::Search.clean_search_text(txt, self.multiple_types_as_one) end |
#filter_mods(klass) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/awesome/triage.rb', line 102 def filter_mods(klass) valid_filter_mods = nil if self.filters # 5. If there is a filter modifier, then make sure it matches the locale being searched or return nil valid_filter_mods = Awesome::Search.protect_filters ? klass.valid_filter_modifiers(self.text, self.filters) : self.filters puts "valid_filter_mods is empty" if Awesome::Triage.verbose && valid_filter_mods.empty? end valid_filter_mods end |
#new_search_for_type_and_locale(klass, type, locale, stopwords) ⇒ Object
single type
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/awesome/triage.rb', line 76 def new_search_for_type_and_locale(klass, type, locale, stopwords) new_search = nil type = self.class.make_symring(type) # 6. If there is a type modifier, then make sure it matches the type being searched or return nil valid_type_mods = Awesome::Search.protect_types ? klass.valid_type_modifiers(self.text, type, self.multiple_types_as_one) : [type] puts "valid_type_mods is empty" if Awesome::Triage.verbose && valid_type_mods.empty? unless valid_type_mods.empty? new_search = klass.new({:stopwords => stopwords, :multiple_types_as_one => self.multiple_types_as_one, :search_text => self.text, :search_type => type, :search_locale => locale, :search_filters => self.filter_mods(klass), :page => self.page, :per_page => self.per_page}) new_search.get_results end return new_search end |
#new_search_for_types_and_locale(klass, types, locale, stopwords) ⇒ Object
multiple types
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/awesome/triage.rb', line 90 def new_search_for_types_and_locale(klass, types, locale, stopwords) new_search = nil # 6. If there is a type modifier, then make sure it matches the type being searched or return nil valid_type_mods = klass.protect_types ? klass.valid_type_modifiers(self.text, types, self.multiple_types_as_one) : types puts "valid_type_mods is empty" if Awesome::Triage.verbose && valid_type_mods.empty? unless valid_type_mods.empty? new_search = klass.new({:stopwords => stopwords, :multiple_types_as_one => self.multiple_types_as_one, :search_text => self.text, :search_type => valid_type_mods, :search_locale => locale, :search_filters => self.filter_mods(klass), :page => self.page, :per_page => self.per_page}) new_search.get_results end return new_search end |