class YnabConvert::CLI

The command line interface methods

Public Class Methods

new() click to toggle source
# File lib/ynab_convert.rb, line 62
def initialize
  @metadata = Metadata.new
  @options = parse_argv
  return unless no_options_given

  show_usage
  exit
end

Public Instance Methods

start() click to toggle source
# File lib/ynab_convert.rb, line 71
def start
  @file = File.new opts
  logger.debug "Using processor `#{@options[:institution]}' => #{processor}"
  @file.to_ynab!
end

Private Instance Methods

no_options_given() click to toggle source
# File lib/ynab_convert.rb, line 109
def no_options_given
  @options[:institution].nil? || @options[:file].nil?
end
opts() click to toggle source
# File lib/ynab_convert.rb, line 79
def opts
  { file: @options[:file], processor: processor }
rescue NameError => e
  raise e unless e.message.match(/#{processor_class_name}/)

  logger.debug "#{@options.to_h}, #{processor_class_name}"
  show_unknown_institution_message
  exit false
end
parse_argv() click to toggle source
# File lib/ynab_convert.rb, line 89
   def parse_argv
     Slop.parse do |o|
       o.on '-v', '--version', 'print the version' do
         puts @metadata.version
         exit
       end
       o.string '-i', '--institution', 'name of the financial institution '\
'that generated the file to convert'
       o.string '-f', '--file', 'path to the csv file to convert'
     end
   end
processor() click to toggle source
# File lib/ynab_convert.rb, line 105
def processor
  processor_class_name.split('::').inject(Object) { |o, c| o.const_get c }
end
processor_class_name() click to toggle source
# File lib/ynab_convert.rb, line 101
def processor_class_name
  "Processor::#{@options[:institution].camel_case}"
end
show_unknown_institution_message() click to toggle source
# File lib/ynab_convert.rb, line 118
def show_unknown_institution_message
  warn 'Could not find any processor for the institution '\
    "`#{@options[:institution]}'. If it's not a typo, consider "\
    'contributing a new processor (see https://github.com/coaxial/'\
    'ynab_convert#contributing to get started).'
end
show_usage() click to toggle source
# File lib/ynab_convert.rb, line 113
def show_usage
  puts @metadata.short_desc
  puts @options
end