class XeroCLI::Commands::Spend
Constants
- TRANSACTION_TYPE
Attributes
as[R]
from[R]
on[R]
spend[R]
to[R]
Public Class Methods
new(options)
click to toggle source
# File lib/xero_cli/commands/spend.rb, line 4 def initialize(options) @spend = options.spend.to_f @to = options.to @from = options.from @on = options.on @as = options.as end
Public Instance Methods
perform()
click to toggle source
# File lib/xero_cli/commands/spend.rb, line 12 def perform check_exceptions account_code = as.nil? ? nil : XeroCLI::AccountsStorage.find_account_code_by_name(as) transaction_attributes = XeroCLI::Templates::Transaction.attributes(spend, TRANSACTION_TYPE, to, from, account_code, on) create_transaction(transaction_attributes) write_to_terminal end
Private Instance Methods
check_exceptions()
click to toggle source
# File lib/xero_cli/commands/spend.rb, line 24 def check_exceptions raise Exception, 'Amount should positive' if spend.negative? || spend.zero? raise Exception, 'Please add "--to NAME"' if to.nil? end
create_transaction(json)
click to toggle source
# File lib/xero_cli/commands/spend.rb, line 38 def create_transaction(json) xero_api.new_transaction(json) end
write_to_terminal()
click to toggle source
# File lib/xero_cli/commands/spend.rb, line 29 def write_to_terminal output = ["Spent #{spend}"] output << "from #{from || XeroCLI::Constants::STRIPE_BANK_NAME}" output << "to #{to}" output << "as #{as}" if as output << "on #{format_date(on)}" if on ap output.join(' ') end