Class: Picture

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

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Picture

Returns a new instance of Picture.



2
3
4
# File 'lib/picture.rb', line 2

def initialize(html)
  @html = html
end

Instance Method Details

#delete_duplicate_picsObject

Deletes duplicate pictures



28
29
30
31
32
33
# File 'lib/picture.rb', line 28

def delete_duplicate_pics
  pics = Dir["pictures/*.jpg.*"]
  pics.each do |p|
    File.delete(p)
  end
end

#pic_pathObject

Download picture



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/picture.rb', line 14

def pic_path
  if picture
    # Get path
    dir = "pictures/"
    full_path = dir+picture.split("/").last.chomp.strip

    # Get file
    `wget -P #{dir} #{picture}` if !File.file?(full_path)
    delete_duplicate_pics
    return full_path
  end
end

#pictureObject

Get path to the picture url



7
8
9
10
11
# File 'lib/picture.rb', line 7

def picture
  pic = @html.css('.profile-picture').css('img').first
  pic_url = pic['src'] ? pic['src'] : pic['data-delayed-url']
  return pic_url
end