module Photomontage

Constants

VERSION

Public Class Methods

begin() click to toggle source
# File lib/photomontage.rb, line 12
def self.begin
              puts Interaction::WELCOME
              keywords = []
              10.times{
                      word = STDIN.gets.chomp
                      break if word == 'exit'
                      keywords << word if !word.empty?
              }
              keywords
      end
respond(keywords) click to toggle source
# File lib/photomontage.rb, line 23
def self.respond(keywords)
        Dir.mkdir 'tmp' unless File.exists?('tmp')
        FileUtils.rm_rf(Dir.glob('tmp/*'))
        puts Interaction::IN_PROGRESS

        keywords.each_with_index do |keyword, index|
                scrape_flickr(keyword, index)
        end
        verify_images_present?
        puts Interaction::FILE_NAME
        file_name = STDIN.gets.chomp
        Flickr.create_collage(file_name)
        FileUtils.rm_rf(Dir.glob('tmp/*'))
        puts Interaction::COMPLETE.gsub('FILE_NAME', file_name)
end

Private Class Methods

pick_random_word(i) click to toggle source
# File lib/photomontage.rb, line 58
def self.pick_random_word(i)
        dictionary = File.read('/usr/share/dict/words').split("\n")
        random_word = dictionary.sample
        scrape_flickr(random_word, i)
end
scrape_flickr(keyword, index) click to toggle source
# File lib/photomontage.rb, line 41
def self.scrape_flickr(keyword, index)
        flickr = Flickr.new(keyword, index)
        result = flickr.search
        flickr.fetch if result
end
verify_images_present?() click to toggle source
# File lib/photomontage.rb, line 47
def self.verify_images_present?
        (0..9).each do |i|
                file = "tmp/#{i}.jpg"
                unless File.exist?(file)
                        while !File.exist?(file)
                                result = pick_random_word(i)
                        end
                end
        end
end