Class: Searchable
- Inherits:
-
Object
- Object
- Searchable
- Defined in:
- lib/classes/searchable.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#raw_name ⇒ Object
Returns the value of attribute raw_name.
Instance Method Summary collapse
- #add_synonyms_to_names ⇒ Object
- #check_regex(searchable_title) ⇒ Object
-
#initialize(hash) ⇒ Searchable
constructor
A new instance of Searchable.
- #names ⇒ Object
- #regex ⇒ Object
- #separate_synonyms ⇒ Object
Constructor Details
#initialize(hash) ⇒ Searchable
Returns a new instance of Searchable.
5 6 7 8 |
# File 'lib/classes/searchable.rb', line 5 def initialize(hash) @raw_name = hash[:raw_name] @duration = hash[:duration] end |
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
3 4 5 |
# File 'lib/classes/searchable.rb', line 3 def duration @duration end |
#raw_name ⇒ Object
Returns the value of attribute raw_name.
3 4 5 |
# File 'lib/classes/searchable.rb', line 3 def raw_name @raw_name end |
Instance Method Details
#add_synonyms_to_names ⇒ Object
14 15 16 17 18 19 |
# File 'lib/classes/searchable.rb', line 14 def add_synonyms_to_names @names = {} separate_synonyms.each do |synonym| @names[synonym] = [] end end |
#check_regex(searchable_title) ⇒ Object
67 68 69 |
# File 'lib/classes/searchable.rb', line 67 def check_regex(searchable_title) !searchable_title.downcase[regex].nil? end |
#names ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/classes/searchable.rb', line 21 def names if @names.nil? add_synonyms_to_names separate_synonyms.length.times do |n| @searchable_words = separate_synonyms[n].downcase.split @searchable_words.each do |word| @names[separate_synonyms[n]] += [stemmed(word)] end end @names else @names end end |
#regex ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/classes/searchable.rb', line 36 def regex if @regex.nil? @separate_regexes = [] separate_synonyms.length.times do |n| @regexes = "" names[separate_synonyms[n]].each do |name| @regexes += '(?=.*' + name + ')' end @regexes += ".*" @separate_regexes += [@regexes] end @regex_count = 0 @separate_regexes.each do |separate_regex| @regex_count += 1 @new_regex = Regexp.new(separate_regex, "i") if @regex_count == 1 @regex = @new_regex else @regex = Regexp.union(@regex, @new_regex) end end @regex else @regex end end |
#separate_synonyms ⇒ Object
10 11 12 |
# File 'lib/classes/searchable.rb', line 10 def separate_synonyms @separate_synonyms ||= @raw_name.split(Regexp.new("(| )\,(| )")) end |