Class: TorrentReactor::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/torrent_reactor/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row = nil) ⇒ Result

Returns a new instance of Result.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/torrent_reactor/result.rb', line 5

def initialize(row = nil)
  link = ''
  date = row.search("/td[1]").inner_text
  title = row.search("/td[2]").inner_text.strip
  raw_filesize = row.search("/td[3]").inner_html
  seeders = row.search("/td[4]").inner_text.to_i
  row.search("/td[2] a").each { |b| link = b.get_attribute('href') if b.get_attribute('href') =~ /download\.php/ }
  leeches = row.search("/td[5]").inner_text.to_i

  size = TorrentReactor::Result.filesize_in_bytes(raw_filesize)

  self.date = date
  self.name = title
  self.link = link
  self.size = size
  self.seeds = seeders
  self.leeches = leeches

end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def category
  @category
end

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def date
  @date
end

#leechesObject

Returns the value of attribute leeches.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def leeches
  @leeches
end

Returns the value of attribute link.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def link
  @link
end

Returns the value of attribute magnet_link.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def magnet_link
  @magnet_link
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def name
  @name
end

#seedsObject

Returns the value of attribute seeds.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def seeds
  @seeds
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def size
  @size
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/torrent_reactor/result.rb', line 3

def status
  @status
end

Class Method Details

.filesize_in_bytes(filesize) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/torrent_reactor/result.rb', line 29

def self.filesize_in_bytes(filesize)
  match = filesize.match(/([\d.]+)(.*)/)

  if match
    raw_size = match[1].to_f

    case match[2].strip
      when /gb/i then
        raw_size * 1000000000
      when /mb/i then
        raw_size * 1000000
      when /kb/i then
        raw_size * 1000
      else
        nil
    end
  else
    nil
  end

end

Instance Method Details

#to_sObject



25
26
27
# File 'lib/torrent_reactor/result.rb', line 25

def to_s
  "<TorrentReactor::Result @name => #{name}, @seeds => #{seeds}, @size => #{size}...>"
end