Class: BackgroundImages::Downloader
- Defined in:
- lib/background_images/downloader.rb
Instance Attribute Summary collapse
-
#download_url ⇒ Object
writeonly
Sets the attribute download_url.
-
#file_extension ⇒ Object
writeonly
Sets the attribute file_extension.
-
#find_image_of ⇒ Object
Returns the value of attribute find_image_of.
-
#save_to_file ⇒ Object
Returns the value of attribute save_to_file.
Instance Method Summary collapse
- #clean ⇒ Object
- #download ⇒ Object
-
#initialize(find_image_of = "Brad Pitt's Ghost", save_to_file = "") ⇒ Downloader
constructor
A new instance of Downloader.
- #standardize(selfie_image) ⇒ Object
Constructor Details
#initialize(find_image_of = "Brad Pitt's Ghost", save_to_file = "") ⇒ Downloader
Returns a new instance of Downloader.
5 6 7 8 |
# File 'lib/background_images/downloader.rb', line 5 def initialize(find_image_of="Brad Pitt's Ghost", save_to_file="") @find_image_of = find_image_of @save_to_file = save_to_file end |
Instance Attribute Details
#download_url=(value) ⇒ Object
Sets the attribute download_url
3 4 5 |
# File 'lib/background_images/downloader.rb', line 3 def download_url=(value) @download_url = value end |
#file_extension=(value) ⇒ Object
Sets the attribute file_extension
3 4 5 |
# File 'lib/background_images/downloader.rb', line 3 def file_extension=(value) @file_extension = value end |
#find_image_of ⇒ Object
Returns the value of attribute find_image_of.
3 4 5 |
# File 'lib/background_images/downloader.rb', line 3 def find_image_of @find_image_of end |
#save_to_file ⇒ Object
Returns the value of attribute save_to_file.
3 4 5 |
# File 'lib/background_images/downloader.rb', line 3 def save_to_file @save_to_file end |
Instance Method Details
#clean ⇒ Object
34 35 36 |
# File 'lib/background_images/downloader.rb', line 34 def clean `find . -type f -name "*.png" -exec convert {} -strip {} \;` end |
#download ⇒ Object
10 11 12 13 |
# File 'lib/background_images/downloader.rb', line 10 def download `curl "#{download_url}" > "#{local_file}.#{file_extension}"` self end |
#standardize(selfie_image) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/background_images/downloader.rb', line 15 def standardize(selfie_image) dimensions = "#{selfie_image.page.width}x#{selfie_image.page.height}" `convert #{local_file}.#{file_extension} -resize '#{dimensions}^' -gravity 'center' -crop '#{dimensions}+0+0' #{local_file}.#{destination_extension}` begin image = Magick::Image.read("#{local_file}.#{destination_extension}") rescue end if command_failed? || image.nil? get_new_background_image download standardize(selfie_image) end self end |