Class: DownloadTV::Filterer
- Inherits:
-
Object
- Object
- DownloadTV::Filterer
- Defined in:
- lib/download_tv/filterer.rb
Overview
Builds and applies filters to the results
Instance Method Summary collapse
-
#filter(shows) ⇒ Object
Iteratively applies filters until they’ve all been applied or applying the next filter would result in no results.
-
#initialize(filters_config) ⇒ Filterer
constructor
A new instance of Filterer.
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 |