class Flico::CommandLineInterface
Public Class Methods
parse_args(args)
click to toggle source
# File lib/flico.rb, line 14 def self.parse_args(args) options = {} OptionParser.new do |opts| opts.banner = "Usage: flico [options] [10 keywords with space as delimiter]" opts.on("-f", "--file_name [FileName]", "Collage FileName") do |f| options[:file_name] = f end end.parse!(args) [args, options] end
start(args)
click to toggle source
# File lib/flico.rb, line 25 def self.start(args) keywords, options = parse_args(args) puts "Given Keywords: #{keywords.join(' ')} with Options: #{options}" resources = validate_resources(keywords, options) App.new(resources).create_collage end
validate_dictionary()
click to toggle source
# File lib/flico.rb, line 53 def self.validate_dictionary dictionary_path = '/usr/share/dict/words' if File.exist?(dictionary_path) dictionary = Dictionary.new(dictionary_path) else STDERR.puts "Performing AutoExit due to missing required dictionary at path: #{dictionary_path}" exit 1 end end
validate_flickr_api()
click to toggle source
# File lib/flico.rb, line 41 def self.validate_flickr_api key, secret = ENV['FLICKR_KEY'], ENV['FLICKR_SECRET'] unless key == nil && secret == nil FlickRaw.api_key = key FlickRaw.shared_secret = secret FlickrCommand.setup(FlickRaw::Flickr.new) else STDERR.puts "Performing AutoExit due to missing required environment variables: FLICKR_KEY and FLICKR_SECRET" exit 1 end end
validate_resources(keywords, options={})
click to toggle source
# File lib/flico.rb, line 32 def self.validate_resources(keywords, options={}) dictionary = validate_dictionary dictionary.append(keywords) col = SaveCollage.new col.output_file_name = options[:file_name] Resource.new(flickr_api: validate_flickr_api, dictionary: dictionary, fetch_image: FetchImage.new, collager: Collager.new, save_collage: col) end