class SaltParser::Swift::Account
Constants
- BALANCE_TYPE
- SIGN
Attributes
account_identification[RW]
closing_balance[RW]
transactions[RW]
Public Class Methods
new()
click to toggle source
# File lib/swift/account.rb, line 15 def initialize @transactions = [] end
Public Instance Methods
parse_account_identification(options)
click to toggle source
# File lib/swift/account.rb, line 27 def parse_account_identification(options) @account_identification = options[:content] end
parse_closing_balance(options)
click to toggle source
# 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_hash()
click to toggle source
# File lib/swift/account.rb, line 19 def to_hash { :account_identification => account_identification, :closing_balance => closing_balance, :transactions => transactions.map(&:to_hash) } end