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.
-
#date ⇒ Object
Returns the value of attribute date.
-
#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.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nyaa/torrent.rb', line 11 def initialize (row = nil) self.tid = row.at_css("link").text[/tid=\d+/].gsub(/\D/,'') self.name = row.at_css("title").text; self.info = row.at_css("guid").text; self.link = row.at_css("link").text; row.at_css("description").text.match(/(\d+)[^\d]+(\d+)[^\d]+(\d+)[^\d]+([^-]+)-?([^-]+)?/){ self.seeders = $1.to_i; self.leechers = $2.to_i; self.downloads = $3.to_i; self.filesize = $4.strip; filter = $5.nil? ? '' : $5.strip.downcase self.status = state(filter) } self.category = row.at_css("category").text; self.date = Time.parse(row.at_css("pubDate")).localtime; end |
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
9 10 11 |
# File 'lib/nyaa/torrent.rb', line 9 def bytes @bytes end |
#category ⇒ Object
Returns the value of attribute category.
8 9 10 |
# File 'lib/nyaa/torrent.rb', line 8 def category @category end |
#date ⇒ Object
Returns the value of attribute date.
8 9 10 |
# File 'lib/nyaa/torrent.rb', line 8 def date @date end |
#downloads ⇒ Object
Returns the value of attribute downloads.
8 9 10 |
# File 'lib/nyaa/torrent.rb', line 8 def downloads @downloads end |
#filesize ⇒ Object
Returns the value of attribute filesize.
7 8 9 |
# File 'lib/nyaa/torrent.rb', line 7 def filesize @filesize end |
#health(leech_weight = 0.5, seed_weight = 1.0) ⇒ Object
Returns the value of attribute health.
9 10 11 |
# File 'lib/nyaa/torrent.rb', line 9 def health @health end |
#info ⇒ Object
Returns the value of attribute info.
6 7 8 |
# File 'lib/nyaa/torrent.rb', line 6 def info @info end |
#leechers ⇒ Object
Returns the value of attribute leechers.
7 8 9 |
# File 'lib/nyaa/torrent.rb', line 7 def leechers @leechers end |
#link ⇒ Object
Returns the value of attribute link.
6 7 8 |
# File 'lib/nyaa/torrent.rb', line 6 def link @link end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/nyaa/torrent.rb', line 6 def name @name end |
#seeders ⇒ Object
Returns the value of attribute seeders.
7 8 9 |
# File 'lib/nyaa/torrent.rb', line 7 def seeders @seeders end |
#status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/nyaa/torrent.rb', line 8 def status @status end |
#tid ⇒ Object
Returns the value of attribute tid.
6 7 8 |
# File 'lib/nyaa/torrent.rb', line 6 def tid @tid end |
Instance Method Details
#state(value) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nyaa/torrent.rb', line 50 def state(value) case value when 'trusted' then status = 'Trusted' when 'remake' then status = 'Remake' when 'a+' then status = 'A+' when '' then status = 'Normal' else status = 'Normal' end status end |
#to_hash ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/nyaa/torrent.rb', line 61 def to_hash hash = {} instance_variables.each do |var| hash[var.to_s.delete("@")] = instance_variable_get(var) end hash end |