Class: MovieFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/movies/filter.rb

Instance Method Summary collapse

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

#cleanerObject



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

#titleObject



11
12
13
# File 'lib/movies/filter.rb', line 11

def title
  @_title ||= cleaner
end

#to_paramObject



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

#yearObject



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