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



55
56
57
58
59
60
61
62
63
# File 'lib/flico.rb', line 55

def self.validate_dictionary
  dictionary_path = '/usr/share/dict/words'
  if File.exist?(dictionary_path)
    Dictionary.new(dictionary_path)
  else
    warn "Performing AutoExit due to missing required dictionary at path: #{dictionary_path}"
    exit 1
  end
end

.validate_flickr_apiObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/flico.rb', line 42

def self.validate_flickr_api
  key = ENV['FLICKR_KEY']
  secret = ENV['FLICKR_SECRET']
  if key.nil? && secret.nil?
    warn 'Performing AutoExit due to missing required environment variables: FLICKR_KEY and FLICKR_SECRET'
    exit 1
  else
    FlickRaw.api_key  = key
    FlickRaw.shared_secret  = secret
    FlickrCommand.setup(FlickRaw::Flickr.new)
  end
end

.validate_resources(keywords, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
# 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:, fetch_image: FetchImage.new,
               collager: Collager.new, save_collage: col)
end