Class: AdLocalize::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



5
6
7
# File 'lib/ad_localize/runner.rb', line 5

def initialize
  @options = OptionHandler.parse
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/ad_localize/runner.rb', line 3

def options
  @options
end

Instance Method Details

#run(args = ARGV) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ad_localize/runner.rb', line 9

def run(args = ARGV)
  LOGGER.log(:info, :black, "OPTIONS : #{options}")
  input_files = (args + [options.dig(:drive_key)]).compact # drive_key can be nil
  if input_files.length.zero?
    LOGGER.log(:error, :red, "No CSV to parse. Use option -h to see how to use this script")
  else
    file_to_parse = args.first
    LOGGER.log(:warn, :yellow, "Only one CSV can be treated - the priority goes to #{file_to_parse}") if input_files.length > 1
    if args.empty?
      options[:drive_file] = CsvFileManager.download_from_drive(options.dig(:drive_key), options.dig(:sheet_id))
      file_to_parse = options.dig(:drive_file)
    end
    CsvFileManager.csv?(file_to_parse) ? export(file_to_parse) : LOGGER.log(:error, :red, "#{file_to_parse} is not a csv")
    CsvFileManager.delete_drive_file(options[:drive_file]) if options[:drive_file]
  end
end