Class: Cmxl::Fields::AccountBalance

Inherits:
Cmxl::Field show all
Defined in:
lib/cmxl/fields/account_balance.rb

Direct Known Subclasses

AvailableBalance, ClosingBalance

Constant Summary

Constants inherited from Cmxl::Field

Cmxl::Field::DATE

Instance Attribute Summary

Attributes inherited from Cmxl::Field

#data, #match, #modifier, #source, #tag

Instance Method Summary collapse

Methods inherited from Cmxl::Field

#add_meta_data, #initialize, #method_missing, parse, parsers, #to_amount, #to_amount_in_cents, #to_date, #to_hash, #to_json

Constructor Details

This class inherits a constructor from Cmxl::Field

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cmxl::Field

Instance Method Details

#amountObject



19
20
21
# File 'lib/cmxl/fields/account_balance.rb', line 19

def amount
  to_amount(data['amount'])
end

#amount_in_centsObject



27
28
29
# File 'lib/cmxl/fields/account_balance.rb', line 27

def amount_in_cents
  to_amount_in_cents(data['amount'])
end

#credit?Boolean



11
12
13
# File 'lib/cmxl/fields/account_balance.rb', line 11

def credit?
  data['funds_code'].to_s.casecmp('C').zero?
end

#dateObject



7
8
9
# File 'lib/cmxl/fields/account_balance.rb', line 7

def date
  to_date(data['date'])
end

#debit?Boolean



15
16
17
# File 'lib/cmxl/fields/account_balance.rb', line 15

def debit?
  !credit?
end

#signObject



23
24
25
# File 'lib/cmxl/fields/account_balance.rb', line 23

def sign
  credit? ? 1 : -1
end

#to_hObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cmxl/fields/account_balance.rb', line 31

def to_h
  super.merge(
    'date' => date,
    'funds_code' => funds_code,
    'credit' => credit?,
    'debit' => debit?,
    'currency' => currency,
    'amount' => amount,
    'amount_in_cents' => amount_in_cents,
    'sign' => sign
  )
end