class LedgerGen::Journal
Attributes
date_format[RW]
Public Class Methods
build(&blk)
click to toggle source
# File lib/ledger_gen/journal.rb, line 11 def self.build(&blk) journal = new blk.call(journal) return journal end
new()
click to toggle source
# File lib/ledger_gen/journal.rb, line 20 def initialize @transactions = T.let([], T::Array[Transaction]) @date_format = T.let('%Y/%m/%d', String) end
Public Instance Methods
pretty_print(ledger_options='')
click to toggle source
# File lib/ledger_gen/journal.rb, line 39 def pretty_print(ledger_options='') if ledger_options == '' ledger_options = %Q{-y "#{date_format}" --sort=date} end IO.popen("ledger #{ledger_options} -f - print", 'r+') do |io| io.write to_s io.close_write io.read end end
to_s()
click to toggle source
# File lib/ledger_gen/journal.rb, line 34 def to_s @transactions.map(&:to_s).join("\n\n") + "\n" end
transaction() { |txn| ... }
click to toggle source
# File lib/ledger_gen/journal.rb, line 26 def transaction(&blk) txn = Transaction.new(date_format) @transactions << txn yield txn end