class Flickollage::Image
Attributes
image[RW]
url[R]
word[R]
Public Class Methods
new(word)
click to toggle source
# File lib/flickollage/image.rb, line 10 def initialize(word) @word = word search_on_flickr(word) end
Public Instance Methods
crop(width, height)
click to toggle source
# File lib/flickollage/image.rb, line 22 def crop(width, height) image.combine_options do |b| b.resize "#{width}x#{height}^" b.gravity 'Center' b.extent "#{width}x#{height}" end end
download()
click to toggle source
# File lib/flickollage/image.rb, line 15 def download logger.debug("Downloading an image: #{url}") @image = MiniMagick::Image.open(url) file_not_found unless @image @image end
Private Instance Methods
file_not_found()
click to toggle source
# File lib/flickollage/image.rb, line 32 def file_not_found raise Error, "Failed to load an image for keyword '#{word}'." end
search_on_flickr(word)
click to toggle source
# File lib/flickollage/image.rb, line 36 def search_on_flickr(word) photo = flickr.photos.search(tags: word, sort: 'interestingness-desc', per_page: 1)[0] raise Error, 'Could not find an image using this keyword' unless photo @url = FlickRaw.url_b(photo) logger.debug("Found an image for keyword '#{word}': #{@url}") rescue FlickRaw::FailedResponse raise ::Flickollage::Error, 'Invalid Flickr API key' end