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
- #check_regex(searchable_title) ⇒ Object
-
#initialize(hash) ⇒ Searchable
constructor
A new instance of Searchable.
- #names ⇒ Object
- #regex ⇒ 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
#check_regex(searchable_title) ⇒ Object
36 37 38 |
# File 'lib/classes/searchable.rb', line 36 def check_regex(searchable_title) !searchable_title.downcase[regex].nil? end |
#names ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/classes/searchable.rb', line 10 def names if @names.nil? @names = [] @searchable_words = @raw_name.downcase.split @searchable_words.each do |word| @names += [stemmed(word)] end @names else @names end end |
#regex ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/classes/searchable.rb', line 23 def regex if @regex.nil? @regexes = "" names.each do |name| @regexes += '(?=.*' + name + ')' end @regexes += ".*" @regex = Regexp.new(@regexes, "i") else @regex end end |