Class: Nyaa::Torrent

Inherits:
Object
  • Object
show all
Defined in:
lib/nyaa/torrent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bytesObject

Returns the value of attribute bytes.



9
10
11
# File 'lib/nyaa/torrent.rb', line 9

def bytes
  @bytes
end

#categoryObject

Returns the value of attribute category.



8
9
10
# File 'lib/nyaa/torrent.rb', line 8

def category
  @category
end

#dateObject

Returns the value of attribute date.



8
9
10
# File 'lib/nyaa/torrent.rb', line 8

def date
  @date
end

#downloadsObject

Returns the value of attribute downloads.



8
9
10
# File 'lib/nyaa/torrent.rb', line 8

def downloads
  @downloads
end

#filesizeObject

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

#infoObject

Returns the value of attribute info.



6
7
8
# File 'lib/nyaa/torrent.rb', line 6

def info
  @info
end

#leechersObject

Returns the value of attribute leechers.



7
8
9
# File 'lib/nyaa/torrent.rb', line 7

def leechers
  @leechers
end

Returns the value of attribute link.



6
7
8
# File 'lib/nyaa/torrent.rb', line 6

def link
  @link
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/nyaa/torrent.rb', line 6

def name
  @name
end

#seedersObject

Returns the value of attribute seeders.



7
8
9
# File 'lib/nyaa/torrent.rb', line 7

def seeders
  @seeders
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/nyaa/torrent.rb', line 8

def status
  @status
end

#tidObject

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_hashObject



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