Class: BankScrap::Cli
- Inherits:
-
Thor
- Object
- Thor
- BankScrap::Cli
- Defined in:
- lib/bank_scrap/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.shared_options ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/bank_scrap/cli.rb', line 6 def self. option :user, default: ENV['BANK_SCRAP_USER'] option :password, default: ENV['BANK_SCRAP_PASSWORD'] option :log, default: false option :debug, default: false # Some bank needs more input, like birthday, this would go here # Usage: # bank_scrap balance BANK_NAME --extra=birthday:01/12/1980 option :extra, type: :hash, default: {} end |
Instance Method Details
#balance(bank) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/bank_scrap/cli.rb', line 20 def balance(bank) initialize_client_for(bank) @client.accounts.each do |account| say "Account: #{account.description} (#{account.iban})", :cyan say "Balance: #{account.balance}", :green end end |
#transactions(bank, iban = nil) ⇒ Object
32 33 34 35 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/bank_scrap/cli.rb', line 32 def transactions(bank, iban = nil) begin start_date = @extra_args.has_key?('from') ? Date.strptime(@extra_args['from'],'%d-%m-%Y') : nil end_date = @extra_args.has_key?('to') ? Date.strptime(@extra_args['to'],'%d-%m-%Y') : nil rescue ArgumentError say "Invalid date format. Correct format d-m-Y", :red end initialize_client_for(bank) account = iban ? @client.account_with_iban(iban) : @client.accounts.first if (!start_date.nil? && !end_date.nil?) if (start_date > end_date) say "From date must be lower than to date", :red exit end transactions = account.fetch_transactions(start_date:start_date, end_date:end_date) else transactions = account.transactions end say "Transactions for: #{account.description} (#{account.iban})", :cyan transactions.each do |transaction| say transaction.to_s, (transaction.amount > Money.new(0) ? :green : :red) end end |