Class: MT940::AccountBalance

Inherits:
Field
  • Object
show all
Defined in:
lib/mt940.rb

Overview

60

Constant Summary collapse

CONTENT =
/^(C|D)(\w{6})(\w{3})(\d{1,12},\d{0,2})$/

Constants inherited from Field

Field::DATE, Field::SHORT_DATE

Instance Attribute Summary collapse

Attributes inherited from Field

#content, #modifier

Instance Method Summary collapse

Methods inherited from Field

for, #initialize

Constructor Details

This class inherits a constructor from MT940::Field

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



138
139
140
# File 'lib/mt940.rb', line 138

def amount
  @amount
end

#balance_typeObject (readonly)

Returns the value of attribute balance_type.



138
139
140
# File 'lib/mt940.rb', line 138

def balance_type
  @balance_type
end

#currencyObject (readonly)

Returns the value of attribute currency.



138
139
140
# File 'lib/mt940.rb', line 138

def currency
  @currency
end

#dateObject (readonly)

Returns the value of attribute date.



138
139
140
# File 'lib/mt940.rb', line 138

def date
  @date
end

#signObject (readonly)

Returns the value of attribute sign.



138
139
140
# File 'lib/mt940.rb', line 138

def sign
  @sign
end

Instance Method Details

#parse_content(content) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/mt940.rb', line 142

def parse_content(content)
  content.match(CONTENT)

  @balance_type =
    case @modifier
    when 'F'
      :start
    when 'M'
      :intermediate
    end

  @sign =
    case $1
    when 'C'
      :credit
    when 'D'
      :debit
    end

  raw_date  = $2
  @currency = $3
  @amount   = parse_amount_in_cents($4)

  @date =
    case raw_date
    when 'ALT', '0'
      nil
    when DATE
      ::Date.new("20#{$1}".to_i, $2.to_i, $3.to_i)
    end
end