Class: Demonoid::Result

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row = []) ⇒ Result

Returns a new instance of Result.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/demonoid/result.rb', line 5

def initialize(row = [])
   self.name = row[0].search('td')[1].search('a').inner_html
   self.detail_link = row[0].search('td')[1].search('a').first.get_attribute('href')
   base_url = "http://www.demonoid.me"
   self.link = base_url + row[1].search('td')[2].search('a').first.get_attribute('href')
   self.magnet_link = base_url + row[1].search('td')[2].search('a')[1].get_attribute('href')
   self.seeds = row[1].search('td')[6].search('font').inner_html.to_i
   self.leeches = row[1].search('td')[7].search('font').inner_html.to_i

   raw_filesize =  row[1].search('td')[3].inner_html
   self.size = Demonoid::Result.filesize_in_bytes(raw_filesize)
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#date_createdObject

Returns the value of attribute date_created.



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

def date_created
  @date_created
end

Returns the value of attribute detail_link.



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

def detail_link
  @detail_link
end

#leechesObject

Returns the value of attribute leeches.



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

def leeches
  @leeches
end

Returns the value of attribute link.



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

def link
  @link
end

Returns the value of attribute magnet_link.



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

def magnet_link
  @magnet_link
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#seedsObject

Returns the value of attribute seeds.



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

def seeds
  @seeds
end

#sizeObject

Returns the value of attribute size.



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

def size
  @size
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Class Method Details

.filesize_in_bytes(filesize) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/demonoid/result.rb', line 22

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



18
19
20
# File 'lib/demonoid/result.rb', line 18

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