Class: Miyuki::Tracker
- Inherits:
-
Object
- Object
- Miyuki::Tracker
- Includes:
- Yamazaki::Core
- Defined in:
- lib/miyuki/tracker.rb
Instance Attribute Summary collapse
-
#torrents ⇒ Object
readonly
Returns the value of attribute torrents.
Instance Method Summary collapse
- #for_every_torrent(&callback) ⇒ Object
-
#initialize(watch_dir, series, &callback) ⇒ Tracker
constructor
A new instance of Tracker.
- #refresh ⇒ Object
- #remove_duplicates_from(other_torrents) ⇒ Object
Constructor Details
#initialize(watch_dir, series, &callback) ⇒ Tracker
Returns a new instance of Tracker.
21 22 23 24 25 26 27 28 29 |
# File 'lib/miyuki/tracker.rb', line 21 def initialize(watch_dir, series, &callback) # TODO: This will raise a warning when the class is initializated twice Yamazaki.const_set(:WATCH_DIR, watch_dir) @series = series || [] @callback = callback if block_given? refresh end |
Instance Attribute Details
#torrents ⇒ Object (readonly)
Returns the value of attribute torrents.
19 20 21 |
# File 'lib/miyuki/tracker.rb', line 19 def torrents @torrents end |
Instance Method Details
#for_every_torrent(&callback) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/miyuki/tracker.rb', line 31 def for_every_torrent(&callback) if block_given? @callback = callback else yield end end |
#refresh ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/miyuki/tracker.rb', line 39 def refresh @torrents = [] fetch_torrents! @torrents.each do |torrent| downloaded = Yamazaki.download_torrent(torrent.title, torrent.link) @callback.call(torrent) if downloaded && @callback end end |
#remove_duplicates_from(other_torrents) ⇒ Object
51 52 53 54 55 |
# File 'lib/miyuki/tracker.rb', line 51 def remove_duplicates_from(other_torrents) other_torrents.delete_if do |torrent| @torrents.select { |other_torrent| torrent.link == other_torrent.link }.any? end end |