Class: NyaaScraper
- Inherits:
-
Object
- Object
- NyaaScraper
- Defined in:
- lib/nyaa_scraper.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize(search) ⇒ NyaaScraper
constructor
A new instance of NyaaScraper.
- #links ⇒ Object
- #magnets ⇒ Object
- #torrents ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(search) ⇒ NyaaScraper
Returns a new instance of NyaaScraper.
8 9 10 11 |
# File 'lib/nyaa_scraper.rb', line 8 def initialize(search) @search = search self.base = "https://nyaa.si" end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
6 7 8 |
# File 'lib/nyaa_scraper.rb', line 6 def base @base end |
Instance Method Details
#html ⇒ Object
17 18 19 |
# File 'lib/nyaa_scraper.rb', line 17 def html uri.read end |
#links ⇒ Object
21 22 23 24 25 |
# File 'lib/nyaa_scraper.rb', line 21 def links Nokogiri::HTML(html)\ .css(".torrent-list tr a") \ .map { |link| link["href"] } end |
#magnets ⇒ Object
27 28 29 |
# File 'lib/nyaa_scraper.rb', line 27 def magnets links.select { |href| href =~ /^magnet/ } end |
#torrents ⇒ Object
31 32 33 34 35 |
# File 'lib/nyaa_scraper.rb', line 31 def torrents links.select { |href| href =~ /\.torrent$/ } \ .map { |href| URI.join self.base, "#{href}" } \ .map { |uri| uri.to_s } end |
#uri ⇒ Object
13 14 15 |
# File 'lib/nyaa_scraper.rb', line 13 def uri URI.join self.base, "?#{@search.querystring}" end |