Class: Nyaa::Torrent
- Inherits:
-
Object
- Object
- Nyaa::Torrent
- Defined in:
- lib/nyaa/torrent.rb
Instance Attribute Summary collapse
-
#bytes ⇒ Object
Returns the value of attribute bytes.
-
#category ⇒ Object
Returns the value of attribute category.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#downloads ⇒ Object
Returns the value of attribute downloads.
-
#filesize ⇒ Object
Returns the value of attribute filesize.
-
#health(leech_weight = 0.5, seed_weight = 1.0) ⇒ Object
Returns the value of attribute health.
-
#info ⇒ Object
Returns the value of attribute info.
-
#leechers ⇒ Object
Returns the value of attribute leechers.
-
#link ⇒ Object
Returns the value of attribute link.
-
#name ⇒ Object
Returns the value of attribute name.
-
#seeders ⇒ Object
Returns the value of attribute seeders.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tid ⇒ Object
Returns the value of attribute tid.
Instance Method Summary collapse
-
#initialize(row = nil) ⇒ Torrent
constructor
A new instance of Torrent.
- #state(value) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(row = nil) ⇒ Torrent
Returns a new instance of Torrent.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nyaa/torrent.rb', line 10 def initialize (row = nil) self.tid = row.css('td.tlistname').at('a')['href'][/tid=\d+/].gsub(/\D/,'') self.name = row.css('td.tlistname').at('a').text.strip self.info = row.css('td.tlistname').at('a')['href'] self.link = row.css('td.tlistdownload').at('a')['href'] self.filesize = row.css('td.tlistsize').text self.seeders = row.css('td.tlistsn').text.to_i self.leechers = row.css('td.tlistln').text.to_i self.status = state(row.values[0]) self.category = row.css('td.tlisticon').at('a')['title'] self.downloads = row.css('td.tlistdn').text self.comments = row.css('td.tlistmn').text end |
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
8 9 10 |
# File 'lib/nyaa/torrent.rb', line 8 def bytes @bytes end |
#category ⇒ Object
Returns the value of attribute category.
7 8 9 |
# File 'lib/nyaa/torrent.rb', line 7 def category @category end |
#comments ⇒ Object
Returns the value of attribute comments.
7 8 9 |
# File 'lib/nyaa/torrent.rb', line 7 def comments @comments end |
#downloads ⇒ Object
Returns the value of attribute downloads.
7 8 9 |
# File 'lib/nyaa/torrent.rb', line 7 def downloads @downloads end |
#filesize ⇒ Object
Returns the value of attribute filesize.
6 7 8 |
# File 'lib/nyaa/torrent.rb', line 6 def filesize @filesize end |
#health(leech_weight = 0.5, seed_weight = 1.0) ⇒ Object
Returns the value of attribute health.
8 9 10 |
# File 'lib/nyaa/torrent.rb', line 8 def health @health end |
#info ⇒ Object
Returns the value of attribute info.
5 6 7 |
# File 'lib/nyaa/torrent.rb', line 5 def info @info end |
#leechers ⇒ Object
Returns the value of attribute leechers.
6 7 8 |
# File 'lib/nyaa/torrent.rb', line 6 def leechers @leechers end |
#link ⇒ Object
Returns the value of attribute link.
5 6 7 |
# File 'lib/nyaa/torrent.rb', line 5 def link @link end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/nyaa/torrent.rb', line 5 def name @name end |
#seeders ⇒ Object
Returns the value of attribute seeders.
6 7 8 |
# File 'lib/nyaa/torrent.rb', line 6 def seeders @seeders end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/nyaa/torrent.rb', line 7 def status @status end |
#tid ⇒ Object
Returns the value of attribute tid.
5 6 7 |
# File 'lib/nyaa/torrent.rb', line 5 def tid @tid end |
Instance Method Details
#state(value) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nyaa/torrent.rb', line 45 def state(value) case value when 'trusted tlistrow' then status = 'Trusted' when 'remake tlistrow' then status = 'Remake' when 'aplus tlistrow' then status = 'A+' when 'tlistrow' then status = 'Normal' else status = 'Normal' end status end |
#to_hash ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/nyaa/torrent.rb', line 56 def to_hash hash = {} instance_variables.each do |var| hash[var.to_s.delete("@")] = instance_variable_get(var) end hash end |