Class: ImageDownloader::Process
- Inherits:
-
Object
- Object
- ImageDownloader::Process
- Defined in:
- lib/image_downloader.rb
Constant Summary collapse
- DEFAULT_USER_AGENT =
'Mozilla/5.0'
Instance Attribute Summary collapse
-
#argument ⇒ Object
Returns the value of attribute argument.
-
#images ⇒ Object
Returns the value of attribute images.
Instance Method Summary collapse
-
#download(*args) ⇒ Object
:(parallel|consequentially) :(parallel|consequentially) => true :user_agent => ‘Mozilla/5.0’.
-
#initialize(url, path) ⇒ Process
constructor
A new instance of Process.
-
#parse(h = {:collect => {}, :ignore_without => {}}) ⇒ Object
:any_looks_like_image => true :regexp => /[^‘“]+.jpg/i :ignore_without => => true Nokogiri gem is required: :collect => => true, :(img_src|a_href|style_url|link_icon) => true :user_agent => ’Mozilla/5.0’.
Constructor Details
Instance Attribute Details
#argument ⇒ Object
Returns the value of attribute argument.
27 28 29 |
# File 'lib/image_downloader.rb', line 27 def argument @argument end |
#images ⇒ Object
Returns the value of attribute images.
27 28 29 |
# File 'lib/image_downloader.rb', line 27 def images @images end |
Instance Method Details
#download(*args) ⇒ Object
:(parallel|consequentially) :(parallel|consequentially) => true :user_agent => ‘Mozilla/5.0’
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/image_downloader.rb', line 67 def download(*args) user_agent = args_hash_and_contain(args, :user_agent) || DEFAULT_USER_AGENT if !args.first || args.first == :parallel || args_hash_and_contain(args, :parallel) Download.parallel(self.images, user_agent) elsif args.first == :consequentially || args_hash_and_contain(args, :consequentially) Download.consequentially(self.images, user_agent) else p "Not correct argument for download method" end end |
#parse(h = {:collect => {}, :ignore_without => {}}) ⇒ Object
:any_looks_like_image => true :regexp => /[^‘“]+.jpg/i :ignore_without => => true Nokogiri gem is required: :collect => => true, :(img_src|a_href|style_url|link_icon) => true :user_agent => ’Mozilla/5.0’
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/image_downloader.rb', line 44 def parse(h={:collect => {}, :ignore_without => {}}) self.rebuild_collect_hash(h) parser = Parser.new(self.argument.url, h[:user_agent] || DEFAULT_USER_AGENT) if h[:any_looks_like_image] parser.get_content_raw parser.get_images_raw(self.argument.path, h[:collect]) elsif h[:regexp] parser.get_content_raw parser.get_images_regexp(self.argument.path, h[:regexp]) else parser.get_content parser.get_images(self.argument.path, h[:collect]) end parser.ignore_file_without(h[:ignore_without]) self.images = parser.images end |