Class: NnmClub::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/nnmClub_api/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, agent = Mechanize.new) ⇒ Search

Returns a new instance of Search.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nnmClub_api/search.rb', line 15

def initialize(query, agent = Mechanize.new)
  form = agent.get(NnmClub::URL).forms.last
  form.field("nm").value = query
  form.checkbox("sd").check
  form.checkbox("a").check
  torrents = form.submit.search(".prow1",".prow2").collect { |row|
    torrent = { 
      :title      => row.css(".topictitle").empty? ? (nil and status=true)  : row.css(".topictitle").text.strip,
      :size       => row.at("td[6]/u").nil? ? nil : row.at("td[6]/u").text.to_i,
      :seeders    => row.css(".seedmed").empty? ? nil : row.css(".seedmed").text.to_i,
      :torrent_id => status ? nil : row.css(".topictitle").first[:href].split("=").last
    }
    torrent unless torrent.any_nil?
  }
  @torrents = torrents

end

Instance Attribute Details

#torrentsObject (readonly)

Returns the value of attribute torrents.



14
15
16
# File 'lib/nnmClub_api/search.rb', line 14

def torrents
  @torrents
end