Sha256: ade249975bdb6a0916a6744ce904baaf94dbbe16770ddb4eeb3c6068b94e33c1
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
# frozen_string_literal: true module Generalis class Transaction < ActiveRecord::Base DoubleEntry = Struct.new(:credit, :debit, :amount_cents, :currency) do def amount Money.from_cents(amount_cents || 0, currency) end def amount=(value) value = Money.from_amount(value, currency) unless value.is_a?(Money) self.amount_cents = value.cents self.currency = value.currency.iso_code end # @return [Array<Entry>] def entries credit, debit = self.credit, self.debit # Reverse the debit/credit accounts when supplied a negative amount. credit, debit = debit, credit if amount.negative? [ # Flip the amount back to positive since we've already swapped accounts. Credit.new(account: credit, amount: amount.abs, pair_id: pair_id), Debit.new(account: debit, amount: amount.abs, pair_id: pair_id) ] end # @return [String] def pair_id @pair_id ||= SecureRandom.uuid end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
generalis-0.1.0 | lib/generalis/transaction/double_entry.rb |