Class: MMImage

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#down_imageObject

Returns the value of attribute down_image.



15
16
17
# File 'lib/download.rb', line 15

def down_image
  @down_image
end

Class Method Details

.down_image(url) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/download.rb', line 31

def self.down_image(url)
	doc = Nokogiri::HTML(open(url))
	select = 'img'
	doc.css(select).each do |img|
		img_url = img['src']
		name = Time.now.to_f.to_s + File.extname(img_url)
		download_file(name, img_url)	
	end
end

.download_file(file_name, url) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/download.rb', line 17

def self.download_file(file_name, url)
	begin
		puts "     Downlanding #{file_name}"
		date = open(url).read
		file = File.new file_name, 'w'
		file << date
		file.flush
		file.close
	rescue => e
		puts "Hello, I'm a error: #{e}"
	end
end