class XeroCLI::Commands::Receive

Constants

TRANSACTION_TYPE

Attributes

as[R]
from[R]
on[R]
receive[R]
to[R]

Public Class Methods

new(options) click to toggle source
# File lib/xero_cli/commands/receive.rb, line 4
def initialize(options)
  @receive = options.receive.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/receive.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(receive, TRANSACTION_TYPE, from, to, 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/receive.rb, line 24
def check_exceptions
  raise Exception, 'Amount should positive' if receive.negative? || receive.zero?
  raise Exception, 'Please add "--from NAME"' if from.nil?
end
create_transaction(json) click to toggle source
# File lib/xero_cli/commands/receive.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/receive.rb, line 29
def write_to_terminal
  output = ["Received #{receive}"]
  output << "from #{from}"
  output << "to #{to || XeroCLI::Constants::STRIPE_BANK_NAME}"
  output << "as #{as}" if as
  output << "on #{format_date(on)}" if on
  ap output.join(' ')
end