Class: LedgerGen::Journal
- Inherits:
-
Object
- Object
- LedgerGen::Journal
- Defined in:
- lib/ledger_gen/journal.rb
Instance Attribute Summary collapse
-
#date_format ⇒ Object
Returns the value of attribute date_format.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Journal
constructor
A new instance of Journal.
- #pretty_print ⇒ Object
- #to_s ⇒ Object
- #transaction {|txn| ... } ⇒ Object
Constructor Details
#initialize ⇒ Journal
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_format ⇒ Object
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
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_print ⇒ Object
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_s ⇒ Object
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
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 |