Class: OFX::Data::Banking::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/ofx/data/banking/transaction.rb

Constant Summary collapse

FIELDS =
[:type, :date_posted, :amount, :bank_account_to, :name, :refnum, :payee_id, :memo].freeze
VALID_TYPES =
[
  :credit, :debit, :int, :div, :fee, :srvchg, :dep, :atm, :pos, :xfer,
  :check, :payment, :cash, :directdep, :directdebit, :repeatpmt, :other
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Transaction

Returns a new instance of Transaction.

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ofx/data/banking/transaction.rb', line 26

def initialize(opts)
  @type = opts.fetch(:type)
  raise ArgumentError, ":type must be one of #{VALID_TYPES.inspect}, was #{@type}" if !VALID_TYPES.include?(@type)
  @date_posted = opts.fetch(:date_posted)
  @amount = BigDecimal.new(opts.fetch(:amount))
  @fitid = opts.fetch(:fitid)
   = opts.fetch(:bank_account_to, nil)
  @name = opts.fetch(:name, nil)
  raise ArgumentError, ":name must be 1-32 characters long" if @name && @name.length > 32
  @refnum = opts.fetch(:refnum, nil)
  raise ArgumentError, ":refnum must be 1-32 characters long" if @refnum && @refnum.length > 32
  @payee_id = opts.fetch(:payee_id, nil)
  raise ArgumentError, ":payee_id must be 1-12 characters long" if @payee_id && @payee_id.length > 12
  @memo = opts.fetch(:memo, nil)
  raise ArgumentError, ":memo must be 1-255 characters long" if @memo && @memo.length > 255
end

Class Method Details

.with_synthetic_fitid(opts) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/ofx/data/banking/transaction.rb', line 14

def self.with_synthetic_fitid(opts)
  input = FIELDS.map { |key|
    opts.fetch(key, "")
  }.map { |value|
    value.respond_to?(:fitid_str) ? value.fitid_str : value.to_s
  }.join("")
  fitid = Digest::SHA1.hexdigest(input)
  new(opts.merge(fitid: fitid))
end

Instance Method Details

#ofx_typeObject



43
44
45
# File 'lib/ofx/data/banking/transaction.rb', line 43

def ofx_type
  :"banking.statement_transaction"
end