Class: Flico::CommandLineInterface

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

Class Method Summary collapse

Class Method Details

.parse_args(args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# 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) ⇒ Object



25
26
27
28
29
30
# 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_dictionaryObject



53
54
55
56
57
58
59
60
61
# 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_apiObject



41
42
43
44
45
46
47
48
49
50
51
# 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 = {}) ⇒ Object



32
33
34
35
36
37
38
39
# 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