Class: DownloadTV::Filterer

Inherits:
Object
  • Object
show all
Defined in:
lib/download_tv/filterer.rb

Overview

Builds and applies filters to the results

Instance Method Summary collapse

Constructor Details

#initialize(filters_config) ⇒ Filterer

Returns a new instance of Filterer.



7
8
9
10
# File 'lib/download_tv/filterer.rb', line 7

def initialize(filters_config)
  @filters = []
  build_filters(filters_config)
end

Instance Method Details

#filter(shows) ⇒ Object

Iteratively applies filters until they’ve all been applied or applying the next filter would result in no results



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/download_tv/filterer.rb', line 15

def filter(shows)
  # shows is tuple (show name, link)
  @filters.each do |f|
    new_shows = shows.reject { |name, _link| f.call(name) }
    # Go to next filter if the filter removes every release
    next if new_shows.empty?

    shows = new_shows
  end

  shows
end