Class: MovieFilter
- Inherits:
-
Object
- Object
- MovieFilter
- Defined in:
- lib/movies/filter.rb
Instance Method Summary collapse
- #cleaner ⇒ Object
-
#initialize(args) ⇒ MovieFilter
constructor
A new instance of MovieFilter.
- #title ⇒ Object
- #to_param ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(args) ⇒ MovieFilter
Returns a new instance of MovieFilter.
2 3 4 |
# File 'lib/movies/filter.rb', line 2 def initialize(args) args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] } end |
Instance Method Details
#cleaner ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/movies/filter.rb', line 24 def cleaner string = @title [/((19|20)\d{2}).*$/, /\./, /\s*-\s*/, /\s{2,}/].each do |regex| string = string.gsub(regex, ' ') end excluded["plain"].each { |clean| string.gsub!(/#{clean}.*$/i, ' ') } excluded["groups"].each { |clean| string.gsub!(/#{clean}.*$/, ' ') } string.strip end |
#title ⇒ Object
11 12 13 |
# File 'lib/movies/filter.rb', line 11 def title @_title ||= cleaner end |
#to_param ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/movies/filter.rb', line 15 def to_param params = {} if year params.merge!(y: year.to_i) end return params end |
#year ⇒ Object
6 7 8 9 |
# File 'lib/movies/filter.rb', line 6 def year @year ||= @title.to_s.match(/((19|20)\d{2})/).to_a[1] @year.to_i if @year end |