Class: StaticImageDownloader::Downloader
- Inherits:
-
Object
- Object
- StaticImageDownloader::Downloader
- Defined in:
- lib/static_image_download.rb
Constant Summary collapse
- @@DEFAULTPATH =
Default path for images
'images'
Instance Attribute Summary collapse
-
#images ⇒ Object
Returns the value of attribute images.
-
#path ⇒ Object
Returns the value of attribute path.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #consequential_download(download_option = 'CURB_EASY', download_timeout = 120, allow_dup_files = true) ⇒ Object
-
#initialize(url, path = @@DEFAULTPATH) ⇒ Downloader
constructor
This is just for info: user_agent - Parse::DEFAULTUSERAGENT = ‘Mozilla/5.0’ parse_timeout - Parse::DEFAULTTIMEOUT = 10 parse_option - Parse::DEFAULTPARSEOPTION = ‘URI_EXTRACT’ # also you can use one ‘NOKOGIRI’ or ‘HPRICOT’ download_timeout - Image::DEFAULTTIMEOUT = 120 Image::DEFAULTDONWLOADOPTION = ‘CURB_EASY’ # also you can use ‘HTTP_GET’ allow_dup_files - dup_file_names = false # don’t get file if exists one allow_dup_files - dup_file_names [DEFAULT option]= true # get file if it exists as new one and add numerical prefix (1,2,3, etc.) to it’s name.
- #parallel_download(download_option = 'CURB_EASY', download_timeout = 120, allow_dup_files = true) ⇒ Object
- #parse_images(parse_option = 'URI_EXTRACT', parse_timeout = 10, user_agent = 'Mozilla/5.0') ⇒ Object
Constructor Details
#initialize(url, path = @@DEFAULTPATH) ⇒ Downloader
This is just for info: user_agent - Parse::DEFAULTUSERAGENT = ‘Mozilla/5.0’ parse_timeout - Parse::DEFAULTTIMEOUT = 10 parse_option - Parse::DEFAULTPARSEOPTION = ‘URI_EXTRACT’ # also you can use one ‘NOKOGIRI’ or ‘HPRICOT’ download_timeout - Image::DEFAULTTIMEOUT = 120 Image::DEFAULTDONWLOADOPTION = ‘CURB_EASY’ # also you can use ‘HTTP_GET’ allow_dup_files - dup_file_names = false # don’t get file if exists one allow_dup_files - dup_file_names [DEFAULT option]= true # get file if it exists as new one and add numerical prefix (1,2,3, etc.) to it’s name
49 50 51 52 53 |
# File 'lib/static_image_download.rb', line 49 def initialize(url, path=@@DEFAULTPATH) @url = url @path = path.nil? ? @@DEFAULTPATH : path @images = [] end |
Instance Attribute Details
#images ⇒ Object
Returns the value of attribute images.
36 37 38 |
# File 'lib/static_image_download.rb', line 36 def images @images end |
#path ⇒ Object
Returns the value of attribute path.
36 37 38 |
# File 'lib/static_image_download.rb', line 36 def path @path end |
#url ⇒ Object
Returns the value of attribute url.
36 37 38 |
# File 'lib/static_image_download.rb', line 36 def url @url end |
Class Method Details
.default_path ⇒ Object
55 56 57 |
# File 'lib/static_image_download.rb', line 55 def self.default_path @@DEFAULTPATH end |
Instance Method Details
#consequential_download(download_option = 'CURB_EASY', download_timeout = 120, allow_dup_files = true) ⇒ Object
75 76 77 78 |
# File 'lib/static_image_download.rb', line 75 def consequential_download(download_option='CURB_EASY', download_timeout=120, allow_dup_files=true) self.images.each { |img| img.download(download_option, download_timeout, :dup_file_names => allow_dup_files) } p "Total " + Images::get_successfull_pictures_number + " pictures were got" end |
#parallel_download(download_option = 'CURB_EASY', download_timeout = 120, allow_dup_files = true) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/static_image_download.rb', line 66 def parallel_download(download_option='CURB_EASY', download_timeout=120, allow_dup_files=true) threads = [] self.images.each do |img| threads << Thread.new(img) { |image| image.download(download_option, download_timeout, :dup_file_names => allow_dup_files) } end threads.each { |aThread| aThread.join } p "Total " + Images::get_successfull_pictures_number + " pictures were got" end |
#parse_images(parse_option = 'URI_EXTRACT', parse_timeout = 10, user_agent = 'Mozilla/5.0') ⇒ Object
59 60 61 62 63 64 |
# File 'lib/static_image_download.rb', line 59 def parse_images(parse_option='URI_EXTRACT', parse_timeout=10, user_agent='Mozilla/5.0') parser = Parser.new(self.url, self.path, parse_option, parse_timeout, user_agent) parser.get_content_raw parser.parse_images self.images = parser.images end |