Class: SaltParser::Swift::Account
Constant Summary collapse
- BALANCE_TYPE =
{ "F" => :start, "M" => :intermediate }
- SIGN =
{ "C" => :credit, "D" => :debit }
Instance Attribute Summary collapse
-
#account_identification ⇒ Object
Returns the value of attribute account_identification.
-
#closing_balance ⇒ Object
Returns the value of attribute closing_balance.
-
#transactions ⇒ Object
Returns the value of attribute transactions.
Instance Method Summary collapse
-
#initialize ⇒ Account
constructor
A new instance of Account.
- #parse_account_identification(options) ⇒ Object
- #parse_closing_balance(options) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Account
Returns a new instance of Account.
15 16 17 |
# File 'lib/swift/account.rb', line 15 def initialize @transactions = [] end |
Instance Attribute Details
#account_identification ⇒ Object
Returns the value of attribute account_identification.
4 5 6 |
# File 'lib/swift/account.rb', line 4 def account_identification @account_identification end |
#closing_balance ⇒ Object
Returns the value of attribute closing_balance.
4 5 6 |
# File 'lib/swift/account.rb', line 4 def closing_balance @closing_balance end |
#transactions ⇒ Object
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 parse_account_identification() @account_identification = [: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() match_data = [: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[[: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 ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/swift/account.rb', line 19 def to_hash { :account_identification => account_identification, :closing_balance => closing_balance, :transactions => transactions.map(&:to_hash) } end |