Class: SepaFileParser::AccountBalance

Inherits:
Object
  • Object
show all
Defined in:
lib/sepa_file_parser/general/account_balance.rb

Instance Method Summary collapse

Constructor Details

#initialize(amount, currency, date, credit = false) ⇒ AccountBalance

Returns a new instance of AccountBalance.

Parameters:



10
11
12
13
14
15
# File 'lib/sepa_file_parser/general/account_balance.rb', line 10

def initialize(amount, currency, date, credit = false)
  @amount = amount
  @currency = currency
  @date = date
  @credit = credit
end

Instance Method Details

#amountBigDecimal

Returns:

  • (BigDecimal)


38
39
40
# File 'lib/sepa_file_parser/general/account_balance.rb', line 38

def amount
  SepaFileParser::Misc.to_amount(@amount)
end

#amount_in_centsInteger

Returns:

  • (Integer)


43
44
45
# File 'lib/sepa_file_parser/general/account_balance.rb', line 43

def amount_in_cents
  SepaFileParser::Misc.to_amount_in_cents(@amount)
end

#credit?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/sepa_file_parser/general/account_balance.rb', line 33

def credit?
  @credit
end

#currencyString

Returns:



18
19
20
# File 'lib/sepa_file_parser/general/account_balance.rb', line 18

def currency
  @currency
end

#dateDate

Returns:

  • (Date)


23
24
25
# File 'lib/sepa_file_parser/general/account_balance.rb', line 23

def date
  Date.parse @date
end

#signInteger

Returns either 1 or -1.

Returns:

  • (Integer)

    either 1 or -1



28
29
30
# File 'lib/sepa_file_parser/general/account_balance.rb', line 28

def sign
  credit? ? 1 : -1
end

#signed_amountBigDecimal

Returns:

  • (BigDecimal)


48
49
50
# File 'lib/sepa_file_parser/general/account_balance.rb', line 48

def signed_amount
  amount * sign
end

#to_hHash{String => BigDecimal, Integer}

Returns:

  • (Hash{String => BigDecimal, Integer})


53
54
55
56
57
58
59
# File 'lib/sepa_file_parser/general/account_balance.rb', line 53

def to_h
  {
    'amount' => amount,
    'amount_in_cents' => amount_in_cents,
    'sign' => sign
  }
end