class TorrentRSS::Feed

Attributes

url[R]

Public Class Methods

new(url) click to toggle source
# File lib/torrent_rss/feed.rb, line 4
def initialize url
  @url = url
end

Public Instance Methods

fetch!(options = {}) click to toggle source
# File lib/torrent_rss/feed.rb, line 8
def fetch! options = {}
  @directory = options[:directory]
  parsed_feed.entries.each do |entry|
    puts "Parsing #{entry.entry_id}" if options[:verbose]
    if new_entry? entry
      puts "Entry #{entry.entry_id} is new! Downloading..." if options[:verbose]
      torrent = Torrent.from_entry entry
      if torrent.download @directory
        puts "Entry #{entry.entry_id} downloaded to #{@directory}!" if options[:verbose]
        EntryLog.add entry.entry_id
      else
        puts "Entry #{entry.entry_id} could not be downloaded" if options[:verbose]
      end
    end
  end
end
new_entry?(entry) click to toggle source
# File lib/torrent_rss/feed.rb, line 25
def new_entry? entry
  !EntryLog.has? entry.entry_id
end
parsed_feed() click to toggle source
# File lib/torrent_rss/feed.rb, line 29
def parsed_feed
  @feed ||= Feedzirra::Feed.fetch_and_parse @url
end
verbose(message) click to toggle source
# File lib/torrent_rss/feed.rb, line 33
def verbose message
  puts message if options[:verbose] 
end