Class: TorrentCrawler::Crawlers::Base
- Inherits:
-
Object
- Object
- TorrentCrawler::Crawlers::Base
- Defined in:
- lib/crawlers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
- #detail(tracker_id) ⇒ Object
- #detail_url ⇒ Object
- #headers ⇒ Object
- #index(last_seen = nil) ⇒ Object
- #index_url ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #result {|torrent| ... } ⇒ Object
- #tracker_key ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
6 7 8 |
# File 'lib/crawlers/base.rb', line 6 def initialize @results = [] end |
Instance Attribute Details
#results ⇒ Object
Returns the value of attribute results.
4 5 6 |
# File 'lib/crawlers/base.rb', line 4 def results @results end |
Instance Method Details
#detail(tracker_id) ⇒ Object
30 31 32 |
# File 'lib/crawlers/base.rb', line 30 def detail(tracker_id) raise BadCrawlerError, "A method named detail has not been implemented in this Crawler class" end |
#detail_url ⇒ Object
22 23 24 |
# File 'lib/crawlers/base.rb', line 22 def detail_url raise BadCrawlerError, "A method named detail_url has not been implemented in this Crawler class" end |
#headers ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/crawlers/base.rb', line 10 def headers { 'User-Agent' => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3", 'Accept-Language' => 'en-us,en;q=0.5', 'Referer' => index_url } end |
#index(last_seen = nil) ⇒ Object
26 27 28 |
# File 'lib/crawlers/base.rb', line 26 def index(last_seen = nil) raise BadCrawlerError, "A method named index has not been implemented in this Crawler class" end |
#index_url ⇒ Object
18 19 20 |
# File 'lib/crawlers/base.rb', line 18 def index_url raise BadCrawlerError, "A method named index_url has not been implemented in this Crawler class" end |
#result {|torrent| ... } ⇒ Object
34 35 36 37 38 39 |
# File 'lib/crawlers/base.rb', line 34 def result(&block) torrent = TorrentCrawler::Torrent.new torrent.tracker_key = self.tracker_key yield torrent end |
#tracker_key ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/crawlers/base.rb', line 41 def tracker_key self.class.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase. gsub(/.*\/([^\/]+)$/, '\1') end |