Class: GoogleImageScraper::FileSaver

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

Instance Method Summary collapse

Instance Method Details

#save(src) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/google_image_scraper/file_saver.rb', line 7

def save(src)
  binary, extname = if src.start_with?('data:')
                      to_file_from_base64(src)
                    else
                      to_file_from_url(src)
                    end
  fname = "#{Digest::MD5.hexdigest(src)[0...10]}.#{extname}"

  File.write(File.join(dir.path, fname), binary)
end