Class: SaltParser::Swift::Transaction

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

Constant Summary collapse

FUNDS_CORE =
{
  "C"  => :credit,
  "D"  => :debit,
  "RC" => :return_credit,
  "RD" => :return_debit
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Transaction

Returns a new instance of Transaction.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/swift/transaction.rb', line 15

def initialize(options)
  match_data = options[:content].match(/^(?<raw_date>\d{6})(?<raw_entry_date>\d{4})?(?<funds_code>C|D|RC|RD)\D?(?<amount>\d{1,12},\d{0,2})(?<swift_code>(?:N|F).{3})(?<reference>NONREF|.{0,16})($|\/\/)(?<transaction_description>.*)/) || {}

  @funds_code              = FUNDS_CORE[match_data[:funds_code]]
  @amount                  = match_data[:amount].gsub(',', '').to_i # amount in cents
  @swift_code              = match_data[:swift_code]
  @reference               = match_data[:reference]
  @transaction_description = match_data[:transaction_description]

  @date       = parse_date(match_data[:raw_date])
  @entry_date = (match_data[:raw_entry_date], @date) if match_data[:raw_entry_date]
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/swift/transaction.rb', line 5

def amount
  @amount
end

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'lib/swift/transaction.rb', line 5

def date
  @date
end

#entry_dateObject (readonly)

Returns the value of attribute entry_date.



5
6
7
# File 'lib/swift/transaction.rb', line 5

def 
  @entry_date
end

#funds_codeObject (readonly)

Returns the value of attribute funds_code.



5
6
7
# File 'lib/swift/transaction.rb', line 5

def funds_code
  @funds_code
end

#infoObject

Returns the value of attribute info.



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

def info
  @info
end

#referenceObject (readonly)

Returns the value of attribute reference.



5
6
7
# File 'lib/swift/transaction.rb', line 5

def reference
  @reference
end

#swift_codeObject (readonly)

Returns the value of attribute swift_code.



5
6
7
# File 'lib/swift/transaction.rb', line 5

def swift_code
  @swift_code
end

#transaction_descriptionObject (readonly)

Returns the value of attribute transaction_description.



5
6
7
# File 'lib/swift/transaction.rb', line 5

def transaction_description
  @transaction_description
end

Instance Method Details

#to_hashObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/swift/transaction.rb', line 28

def to_hash
  {
    :date                    => date,
    :entry_date              => ,
    :funds_code              => funds_code,
    :amount                  => amount,
    :swift_code              => swift_code,
    :reference               => reference,
    :transaction_description => transaction_description,
    :info                    => info.try(:to_hash)
  }
end