Class: LedgerGen::Journal
- Inherits:
-
Object
- Object
- LedgerGen::Journal
- Extended by:
- T::Sig
- 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(ledger_options = '') ⇒ Object
- #to_s ⇒ Object
- #transaction {|txn| ... } ⇒ Object
Constructor Details
#initialize ⇒ Journal
Returns a new instance of Journal.
20 21 22 23 |
# 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 |
Instance Attribute Details
#date_format ⇒ Object
Returns the value of attribute date_format.
8 9 10 |
# File 'lib/ledger_gen/journal.rb', line 8 def date_format @date_format end |
Class Method Details
.build(&blk) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/ledger_gen/journal.rb', line 11 def self.build(&blk) journal = new blk.call(journal) return journal end |
Instance Method Details
#pretty_print(ledger_options = '') ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ledger_gen/journal.rb', line 39 def pretty_print(='') if == '' = %Q{-y "#{date_format}" --sort=date} end IO.popen("ledger #{} -f - print", 'r+') do |io| io.write to_s io.close_write io.read end end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/ledger_gen/journal.rb', line 34 def to_s @transactions.map(&:to_s).join("\n\n") + "\n" end |
#transaction {|txn| ... } ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ledger_gen/journal.rb', line 26 def transaction(&blk) txn = Transaction.new(date_format) @transactions << txn yield txn end |