Class: SaltParser::Swift::Transaction
- Inherits:
-
Object
- Object
- SaltParser::Swift::Transaction
- 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
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#entry_date ⇒ Object
readonly
Returns the value of attribute entry_date.
-
#funds_code ⇒ Object
readonly
Returns the value of attribute funds_code.
-
#info ⇒ Object
Returns the value of attribute info.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#swift_code ⇒ Object
readonly
Returns the value of attribute swift_code.
-
#transaction_description ⇒ Object
readonly
Returns the value of attribute transaction_description.
Instance Method Summary collapse
-
#initialize(options) ⇒ Transaction
constructor
A new instance of Transaction.
- #to_hash ⇒ Object
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() match_data = [: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 = parse_entry_date(match_data[:raw_entry_date], @date) if match_data[:raw_entry_date] end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
5 6 7 |
# File 'lib/swift/transaction.rb', line 5 def amount @amount end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
5 6 7 |
# File 'lib/swift/transaction.rb', line 5 def date @date end |
#entry_date ⇒ Object (readonly)
Returns the value of attribute entry_date.
5 6 7 |
# File 'lib/swift/transaction.rb', line 5 def entry_date @entry_date end |
#funds_code ⇒ Object (readonly)
Returns the value of attribute funds_code.
5 6 7 |
# File 'lib/swift/transaction.rb', line 5 def funds_code @funds_code end |
#info ⇒ Object
Returns the value of attribute info.
4 5 6 |
# File 'lib/swift/transaction.rb', line 4 def info @info end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
5 6 7 |
# File 'lib/swift/transaction.rb', line 5 def reference @reference end |
#swift_code ⇒ Object (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_description ⇒ Object (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_hash ⇒ Object
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 => entry_date, :funds_code => funds_code, :amount => amount, :swift_code => swift_code, :reference => reference, :transaction_description => transaction_description, :info => info.try(:to_hash) } end |