Class: SaltParser::Swift::Account

Inherits:
Base
  • Object
show all
Defined in:
lib/swift/account.rb

Constant Summary collapse

BALANCE_TYPE =
{
  "F" => :start,
  "M" => :intermediate
}
SIGN =
{
  "C" => :credit,
  "D" => :debit
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAccount

Returns a new instance of Account.



15
16
17
# File 'lib/swift/account.rb', line 15

def initialize
  @transactions = []
end

Instance Attribute Details

#account_identificationObject

Returns the value of attribute account_identification.



4
5
6
# File 'lib/swift/account.rb', line 4

def 
  @account_identification
end

#closing_balanceObject

Returns the value of attribute closing_balance.



4
5
6
# File 'lib/swift/account.rb', line 4

def closing_balance
  @closing_balance
end

#transactionsObject

Returns the value of attribute transactions.



4
5
6
# File 'lib/swift/account.rb', line 4

def transactions
  @transactions
end

Instance Method Details

#parse_account_identification(options) ⇒ Object



27
28
29
# File 'lib/swift/account.rb', line 27

def (options)
  @account_identification = options[:content]
end

#parse_closing_balance(options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/swift/account.rb', line 31

def parse_closing_balance(options)
  match_data = options[:content].match(/^(?<sign>C|D)(?<raw_date>\w{6})(?<currency>\w{3})(?<amount>\d{1,12},\d{0,2})$/) || {}
  hash                = {}
  hash[:balance_type] = BALANCE_TYPE[options[:modifier]]
  hash[:sign]         = SIGN[match_data[:sign]]
  hash[:currency]     = match_data[:currency]
  hash[:amount]       = match_data[:amount].gsub(',', '').to_i #amount in cents

  date = match_data[:raw_date].match(/(?<year>\d{2})(?<month>\d{2})(?<day>\d{2})/) rescue nil
  hash[:date] = Date.new(2000 + date[:year].to_i, date[:month].to_i, date[:day].to_i) rescue nil

  @closing_balance = hash
end

#to_hashObject



19
20
21
22
23
24
25
# File 'lib/swift/account.rb', line 19

def to_hash
  {
    :account_identification => ,
    :closing_balance        => closing_balance,
    :transactions           => transactions.map(&:to_hash)
  }
end