class PhotoFlick::CollageMaker

This class responsible to create collage from flickr images

Public Instance Methods

make!() click to toggle source

Main triggering method

# File lib/photo_flick/collage_maker.rb, line 7
def make!
  get_inputs
  puts 'Please wait while processing images...'
  find_images
  create_collage
  puts "Succesfully generated collage image #{Dir.pwd}/#{@output_file}"
  # clean up temp folder
  FileUtils.rm_rf('tmp')
end

Private Instance Methods

create_collage() click to toggle source
# File lib/photo_flick/collage_maker.rb, line 40
def create_collage
  PhotoFlick::ImageProcessor.new(@output_file).create_collage!
rescue => e
  raise "Error while processing images: #{e.message}"
end
find_images() click to toggle source
# File lib/photo_flick/collage_maker.rb, line 34
def find_images
  PhotoFlick::FlickrImageFetcher.new(@keywords).fetch_images!
rescue => e
  raise "Error while fetching images: #{e.message}"
end
get_inputs() click to toggle source

Read inputs from user

# File lib/photo_flick/collage_maker.rb, line 20
def get_inputs
  @keywords = []
  puts 'Enter your search keywords line by line:'
  10.times { @keywords << gets.chomp }
  @keywords.reject!(&:empty?)
  puts 'Enter output file name with extension (JPG|PNG|GIF)'
  loop do
    @output_file = gets.chomp
    @output_file = 'output.jpg' if @output_file.empty?
    break if valid_output_file?(@output_file)
    puts 'Sorry! This file format not supported.'
  end
end
valid_output_file?(file) click to toggle source
# File lib/photo_flick/collage_maker.rb, line 46
def valid_output_file?(file)
  %w(.jpg .png .gif).include? File.extname(file)
end