Class: Bankscrap::CLI

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

Constant Summary collapse

SPACER =
(' ' * 3).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.shared_optionsObject



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

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

Instance Method Details

#balance(bank) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bankscrap/cli.rb', line 22

def balance(bank)
  assign_shared_options
  initialize_client_for(bank)

  if options[:format]
    export_to_file(nil, @client.accounts, options[:format], options[:output])
  else
    @client.accounts.each do ||
      say "Account: #{.description} (#{.iban})", :cyan
      say "Balance: #{.balance.format}", :green
      if .balance != .available_balance
        say "Available: #{.available_balance.format}", :yellow
      end
    end
  end
end

#cards(bank) ⇒ Object



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

def cards(bank)
  assign_shared_options
  initialize_client_for(bank)

  if options[:format]
    export_to_file(nil, @client.cards, options[:format], options[:output])
  else
    @client.cards.each do |card|
      say "Card: #{card.name} #{card.description} #{card.amount.format}", :green
    end
  end
end

#loans(bank) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bankscrap/cli.rb', line 56

def loans(bank)
  assign_shared_options
  initialize_client_for(bank)

  if options[:format]
    export_to_file(nil, @client.loans, options[:format], options[:output])
  else
    @client.loans.each do |loan|
      say "Loan: #{loan.name} #{loan.description} #{loan.amount.format}", :green
    end
  end
end

#transactions(bank) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/bankscrap/cli.rb', line 72

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

  if options[:format]
    export_to_file(, transactions, options[:format], options[:output])
  else
    say "Transactions for: #{.description} (#{.iban})", :cyan
    print_transactions_header
    transactions.each { |t| print_transaction(t) }
  end
end