class Cmxl::Fields::Transaction

Attributes

details[RW]

Public Instance Methods

add_meta_data(content) click to toggle source
# File lib/cmxl/fields/transaction.rb, line 9
def add_meta_data(content)
  self.details = Cmxl::Fields::StatementDetails.parse(content) unless content.nil?
end
amount() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 49
def amount
  to_amount(data['amount'])
end
amount_in_cents() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 53
def amount_in_cents
  to_amount_in_cents(data['amount'])
end
bic() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 109
def bic
  details.bic if details
end
charges_currency() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 95
def charges_currency
  supplementary.charges_currency
end
charges_in_cents() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 91
def charges_in_cents
  supplementary.charges_in_cents
end
credit?() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 17
def credit?
  data['funds_code'].to_s.casecmp('C').zero?
end
date() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 57
def date
  to_date(data['date'])
end
debit?() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 21
def debit?
  data['funds_code'].to_s.casecmp('D').zero?
end
description() click to toggle source

Fields from details

# File lib/cmxl/fields/transaction.rb, line 101
def description
  details.description if details
end
entry_date() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 61
def entry_date
  return if !date || !data['entry_date']

  e_date = to_date(data['entry_date'], date.year)
  # we assume that valuta (date) and entry_date have a close connection. so valuta and entry_date should not be
  # further apart than one month. this leads to some edge cases

  # valuta is in january while entry_date is in december => entry_date was done the year before
  e_date = to_date(data['entry_date'], date.year - 1) if date.month == 1 && e_date.month == 12

  # valuta is in december but entry_date is in january => entry_date is actually in the year after valuta
  e_date = to_date(data['entry_date'], date.year + 1) if date.month == 12 && e_date.month == 1

  e_date
end
funds_code() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 37
def funds_code
  data.values_at('storno_flag', 'funds_code').join
end
iban() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 117
def iban
  details.iban if details
end
information() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 105
def information
  details.information if details
end
initial_amount_in_cents() click to toggle source

Fields from supplementary

# File lib/cmxl/fields/transaction.rb, line 83
def initial_amount_in_cents
  supplementary.initial_amount_in_cents
end
initial_currency() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 87
def initial_currency
  supplementary.initial_currency
end
name() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 113
def name
  details.name if details
end
primanota() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 129
def primanota
  details.primanota if details
end
sepa() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 121
def sepa
  details.sepa if details
end
sha() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 13
def sha
  Digest::SHA2.new.update(source).to_s
end
sign() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 45
def sign
  credit? ? 1 : -1
end
storno?() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 33
def storno?
  !storno_flag.empty?
end
storno_credit?() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 25
def storno_credit?
  credit? && storno?
end
storno_debit?() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 29
def storno_debit?
  debit? && storno?
end
storno_flag() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 41
def storno_flag
  data['storno_flag']
end
sub_fields() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 125
def sub_fields
  details.sub_fields if details
end
supplementary() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 77
def supplementary
  @supplementary ||= Cmxl::Fields::TransactionSupplementary.parse(data['supplementary'])
end
to_h() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 133
def to_h
  {
    'sha' => sha,
    'date' => date,
    'entry_date' => entry_date,
    'amount' => amount,
    'amount_in_cents' => amount_in_cents,
    'sign' => sign,
    'debit' => debit?,
    'credit' => credit?,
    'storno' => storno?,
    'funds_code' => funds_code,
    'swift_code' => swift_code,
    'reference' => reference,
    'bank_reference' => bank_reference,
    'currency_letter' => currency_letter
  }.tap do |h|
    h.merge!(details.to_h) if details
    h.merge!(supplementary.to_h) if supplementary.source
  end
end
to_hash() click to toggle source
# File lib/cmxl/fields/transaction.rb, line 155
def to_hash
  to_h
end
to_json(*args) click to toggle source
# File lib/cmxl/fields/transaction.rb, line 159
def to_json(*args)
  to_h.to_json(*args)
end