Class: RVGP::Fakers::FakeJournal
- Inherits:
-
Faker::Base
- Object
- Faker::Base
- RVGP::Fakers::FakeJournal
- Extended by:
- FakerHelpers
- Defined in:
- lib/rvgp/fakers/fake_journal.rb
Overview
Contains faker implementation(s) that produce pta journals
Class Method Summary collapse
-
.basic_cash(from: ::Date.today, to: from + 9, sum: '$ 100.00'.to_commodity, post_count: 10, postings: []) ⇒ RVGP::Journal
Generates a basic journal, that credits/debits from a Cash account.
Class Method Details
.basic_cash(from: ::Date.today, to: from + 9, sum: '$ 100.00'.to_commodity, post_count: 10, postings: []) ⇒ RVGP::Journal
Generates a basic journal, that credits/debits from a Cash account
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rvgp/fakers/fake_journal.rb', line 23 def basic_cash(from: ::Date.today, to: from + 9, sum: '$ 100.00'.to_commodity, post_count: 10, postings: []) raise StandardError unless sum.is_a?(RVGP::Journal::Commodity) amount_increment = (sum / post_count).floor sum.precision running_sum = nil generated_postings = entries_over_date_range(from, to, post_count).map.with_index do |date, i| post_amount = i + 1 == post_count ? (sum - running_sum) : amount_increment running_sum = running_sum.nil? ? post_amount : (running_sum + post_amount) simple_posting date, post_amount end RVGP::Journal.new((postings + generated_postings).sort_by(&:date)) end |