class ImgOverlay::ImageDownloader
Public Class Methods
new(url:, path:)
click to toggle source
# File lib/img_overlay/image_downloader.rb, line 7 def initialize(url:, path:) @image_url = url @full_file_path = path end
Public Instance Methods
download!()
click to toggle source
# File lib/img_overlay/image_downloader.rb, line 12 def download! open_uri_file_object = get_file_object if open_uri_file_object.nil? return false else if file_acceptable?(open_uri_file_object) save_file open_uri_file_object return true else return false end end end
Private Instance Methods
accepted_mime_types()
click to toggle source
# File lib/img_overlay/image_downloader.rb, line 50 def accepted_mime_types ['image/gif', 'image/jpeg', 'image/png'] end
file_acceptable?(open_uri_file_object)
click to toggle source
# File lib/img_overlay/image_downloader.rb, line 42 def file_acceptable?(open_uri_file_object) if open_uri_file_object.status[0] == "200" && accepted_mime_types.include?(open_uri_file_object.content_type) return true else return false end end
get_file_object()
click to toggle source
# File lib/img_overlay/image_downloader.rb, line 34 def get_file_object begin return open(@image_url) rescue return nil end end
save_file(open_uri_file_object)
click to toggle source
# File lib/img_overlay/image_downloader.rb, line 28 def save_file open_uri_file_object File.open(@full_file_path, 'wb') do |fo| fo.write open_uri_file_object.read end end