Class: LedgerGen::Journal

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_gen/journal.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJournal

Returns a new instance of Journal.



13
14
15
16
# File 'lib/ledger_gen/journal.rb', line 13

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

Instance Attribute Details

#date_formatObject

Returns the value of attribute date_format.



3
4
5
# File 'lib/ledger_gen/journal.rb', line 3

def date_format
  @date_format
end

Class Method Details

.build {|journal| ... } ⇒ Object

Yields:

  • (journal)


5
6
7
8
9
10
11
# File 'lib/ledger_gen/journal.rb', line 5

def self.build
  journal = new
  
  yield journal

  return journal
end

Instance Method Details

#pretty_printObject



29
30
31
32
33
34
35
# File 'lib/ledger_gen/journal.rb', line 29

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

#to_sObject



25
26
27
# File 'lib/ledger_gen/journal.rb', line 25

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

#transaction {|txn| ... } ⇒ Object

Yields:

  • (txn)


18
19
20
21
22
23
# File 'lib/ledger_gen/journal.rb', line 18

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

  yield txn
end