Sha256: f29c8ece118228e246e1473bbf871b943537aa44b9feecf63f65eb3eeecd3d27

Contents?: true

Size: 828 Bytes

Versions: 2

Compression:

Stored size: 828 Bytes

Contents

# frozen_string_literal: true
module Ldgr
  # Builds a transaction
  #
  # Examples
  #
  #   Transaction.new do |t|
  #     t.payee = "Something"
  #     t.amount = 1000
  #     t.date = Date.today + 1
  #   end
  #   # => <class Transaction @payee="Something", @amount=1000, @date=Date.today + 1>
  #
  # Returns a transaction.
  class Transaction
    attr_accessor :payee, :amount, :account, :equity, :date, :effective, :currency, :cleared

    def initialize(&block)
      yield self if block_given?
    end

    def to_s
      <<~HERE
      #{date} #{cleared}#{payee}
        #{account}  #{currency}#{amount}
        #{equity}
      HERE
    end

    def valid?
      return false if String(payee).empty?
      return false if String(amount).empty?
      return false if String(account).empty?
      true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ldgr-0.2.2 lib/ldgr/transaction.rb
ldgr-0.2.1 lib/ldgr/transaction.rb