Class: Bankscrap::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.shared_optionsObject



9
10
11
12
13
14
15
16
# File 'lib/bankscrap/cli.rb', line 9

def self.shared_options
  option :credentials, default: {}, type: :hash
  option :log,         default: false
  option :debug,       default: false
  option :iban,        default: nil
  option :format
  option :output
end

Instance Method Details

#balance(bank) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bankscrap/cli.rb', line 20

def balance(bank)
  assign_shared_options
  initialize_client_for(bank)

  @client.accounts.each do ||
    say "Account: #{account.description} (#{account.iban})", :cyan
    say "Balance: #{account.balance.format}", :green
    if .balance != .available_balance
      say "Available: #{account.available_balance.format}", :yellow
    end
  end
end

#transactions(bank) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bankscrap/cli.rb', line 36

def transactions(bank)
  assign_shared_options

  start_date = parse_date(options[:from]) if options[:from]
  end_date = parse_date(options[:to]) if options[:to]

  initialize_client_for(bank)

   = @iban ? @client.(@iban) : @client.accounts.first

  if start_date && end_date
    if start_date > end_date
      say 'From date must be lower than to date', :red
      exit
    end

    transactions = .fetch_transactions(start_date: start_date, end_date: end_date)
  else
    transactions = .transactions
  end

  export_to_file(transactions, options[:format], options[:output]) if options[:format]

  say "Transactions for: #{account.description} (#{account.iban})", :cyan
  print_transactions_header
  transactions.each { |t| print_transaction(t) }
end