Class: NnmClub::Search
- Inherits:
-
Object
- Object
- NnmClub::Search
- Defined in:
- lib/nnmClub_api/search.rb
Instance Attribute Summary collapse
-
#torrents ⇒ Object
readonly
Returns the value of attribute torrents.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(query, category = nil) ⇒ Search
constructor
A new instance of Search.
Constructor Details
#initialize(query, category = nil) ⇒ Search
Returns a new instance of Search.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nnmClub_api/search.rb', line 21 def initialize(query, category = nil) torrents = [] query = URI.escape(query) @url = NnmClub::URL+"nm=#{query}"+(!category.nil? ? "&c=#{category}" : "") document = Nokogiri::HTML(open(@url)) document.css("table.forumline.tablesorter").css(".prow1",".prow2").each { |row| size = row.at("td[6]/u").nil? ? nil : row.at("td[6]/u").text.to_i title = row.css(".topictitle").empty? ? nil : row.css(".topictitle").text.strip seeders = row.css(".seedmed").empty? ? nil : row.css(".seedmed").text.to_i leechers = row.css(".leechmed").empty? ? nil : row.css(".leechmed").text.to_i torrent_id = row.css(".topictitle").empty? ? nil : row.css(".topictitle").first[:href].split("=").last torrent = { :title => title, :size => size, :seeders => seeders, :leechers => leechers, :torrent_id => torrent_id, :tracker => NnmClub::ID } torrents.push(torrent) unless torrent.any_nil? } @torrents = torrents end |
Instance Attribute Details
#torrents ⇒ Object (readonly)
Returns the value of attribute torrents.
20 21 22 |
# File 'lib/nnmClub_api/search.rb', line 20 def torrents @torrents end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
20 21 22 |
# File 'lib/nnmClub_api/search.rb', line 20 def url @url end |