Sha256: 5967fe6ab20cb2eb3966f72bf53574f83d2991fce22863ae1f525800d00473a9

Contents?: true

Size: 600 Bytes

Versions: 2

Compression:

Stored size: 600 Bytes

Contents

module LedgerGen
  class Journal
    attr_accessor :date_format

    def self.build
      journal = new
  
      yield journal

      return journal
    end
    
    def initialize
      @transactions = []
      @date_format = '%Y/%m/%d'
    end

    def transaction
      txn = Transaction.new(date_format)
      @transactions << txn

      yield txn
    end

    def to_s
      @transactions.map(&:to_s).join("\n\n") + "\n"
    end

    def pretty_print
      IO.popen("ledger -f - print", mode='r+') do |io|
        io.write to_s
        io.close_write
        io.read
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ledger_gen-0.1.2 lib/ledger_gen/journal.rb
ledger_gen-0.1.1 lib/ledger_gen/journal.rb