Class: Ynap::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ynap/cli.rb

Constant Summary collapse

DEFAULT_CONFIG_PATH =
'ynap.yml'

Instance Method Summary collapse

Instance Method Details

#balancesObject



39
40
41
42
43
44
45
46
# File 'lib/ynap/cli.rb', line 39

def balances
  load_config options.config
  if options.bank.nil?
    puts Bank.accounts_descriptions
  else
    puts Bank.find(options.bank).accounts_descriptions
  end
end

#consoleObject



15
16
17
# File 'lib/ynap/cli.rb', line 15

def console
  system("ruby #{File.expand_path File.dirname(__FILE__)}/../../bin/console")
end

#diff(bank_id) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ynap/cli.rb', line 51

def diff(bank_id)
  load_config options.config
  bank = Bank.find(bank_id)
  puts "**************\n* Last #{options.limit} transactions for each account @ #{bank.name}\n**************"
  bank.accounts.each do ||
    puts "\nAccount: #{.description}\n"
    puts "\nPlaid\n-------"
    puts .plaid_transactions.first(options.limit).map(&:description).join("\n")
    puts "\nYNAB\n-------"
    puts .ynab_transactions.first(options.limit).map(&:description).join("\n")
    puts "\n*******"
  end
end

#importObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ynap/cli.rb', line 69

def import
  load_config options.config
  puts "* Fetching transactions and preparing import\n"
  if options.bank.nil?
    Bank.all.each(&:import)
  else
    Bank.find(options.bank).import
  end
  if options.reconcile
    puts "\n* Fetching balances\n"
    balances
  end
end

#payeesObject



87
88
89
90
91
92
93
94
95
# File 'lib/ynap/cli.rb', line 87

def payees
  load_config options.config
  if options.bank.nil?
    puts Bank.payees(with_memos: options.memos).join("\n")
  else

    puts Bank.find(options.bank).send(options.memos ? :payees_memos : :payees).join("\n")
  end
end

#plaidObject



21
22
23
# File 'lib/ynap/cli.rb', line 21

def plaid
  system("ruby #{File.expand_path File.dirname(__FILE__)}/../../bin/plaid #{options.config}")
end

#plaid_ids(bank_id) ⇒ Object



31
32
33
34
# File 'lib/ynap/cli.rb', line 31

def plaid_ids(bank_id)
  load_config options.config
  puts Bank.find(bank_id).all_plaid_ids
end

#transactions(bank_id) ⇒ Object



100
101
102
103
104
105
# File 'lib/ynap/cli.rb', line 100

def transactions(bank_id)
  load_config options.config
  bank = Bank.find bank_id
  scope = options.side == 'ynab' ? :ynab_transactions : :plaid_transactions
  puts bank.send(scope).map(&:description).join("\n")
end