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.



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

#bytesObject

Returns the value of attribute bytes.



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

def bytes
  @bytes
end

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#commentsObject

Returns the value of attribute comments.



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

def comments
  @comments
end

#downloadsObject

Returns the value of attribute downloads.



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

def downloads
  @downloads
end

#filesizeObject

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

#infoObject

Returns the value of attribute info.



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

def info
  @info
end

#leechersObject

Returns the value of attribute leechers.



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

def leechers
  @leechers
end

Returns the value of attribute link.



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

def link
  @link
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#seedersObject

Returns the value of attribute seeders.



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

def seeders
  @seeders
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#tidObject

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_hashObject



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