Class: RVGP::Base::JournalValidation
- Inherits:
-
Validation
- Object
- Validation
- RVGP::Base::JournalValidation
- Includes:
- Application::DescendantRegistry
- Defined in:
- lib/rvgp/base/validation.rb
Overview
A base class, from which your journal validations should inherit. For more information on validations, and your options, see the documentation notes on JournalValidation.
Direct Known Subclasses
Validations::BalanceValidation, Validations::DuplicateTagsValidation, Validations::UncategorizedValidation
Instance Attribute Summary collapse
-
#reconciler ⇒ RVGP::Reconcilers::CsvReconciler, RVGP::Reconcilers::JournalReconciler
readonly
The reconciler whose output will be inspected by this journal validation instance.
Attributes inherited from Validation
Instance Method Summary collapse
-
#initialize(reconciler) ⇒ JournalValidation
constructor
Create a new Journal Validation.
-
#validate_no_balance(with_error_msg, account) ⇒ Object
This helper method will supply the provided account to pta.balance.
-
#validate_no_transactions(with_error_msg, *args) ⇒ Object
This helper method will supply the provided arguments to pta.register.
Methods inherited from Validation
Methods included from Pta::AvailabilityHelper
Constructor Details
#initialize(reconciler) ⇒ JournalValidation
Create a new Journal Validation
179 180 181 182 |
# File 'lib/rvgp/base/validation.rb', line 179 def initialize(reconciler) super() @reconciler = reconciler end |
Instance Attribute Details
#reconciler ⇒ RVGP::Reconcilers::CsvReconciler, RVGP::Reconcilers::JournalReconciler (readonly)
The reconciler whose output will be inspected by this journal validation instance.
169 170 171 |
# File 'lib/rvgp/base/validation.rb', line 169 def reconciler @reconciler end |
Instance Method Details
#validate_no_balance(with_error_msg, account) ⇒ Object
This helper method will supply the provided account to pta.balance. And if there is a balance returned, the supplied error message will be added to our :errors colection, citing the balance that was encountered.
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/rvgp/base/validation.rb', line 209 def validate_no_balance(with_error_msg, account) results = pta.balance account, file: reconciler.output_file error_citations = results.accounts.map do |ra| ra.amounts.map { |commodity| [ra.fullname, RVGP.pastel.red('━'), commodity.to_s].join(' ') } end error_citations.flatten! error! with_error_msg, error_citations unless error_citations.empty? end |
#validate_no_transactions(with_error_msg, *args) ⇒ Object
This helper method will supply the provided arguments to pta.register. And if there are any transactions returned, the supplied error message will be added to our :errors colection, citing the transactions that were encountered.
190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/rvgp/base/validation.rb', line 190 def validate_no_transactions(with_error_msg, *args) ledger_opts = args.last.is_a?(Hash) ? args.pop : {} results = pta.register(*args, { file: reconciler.output_file }.merge(ledger_opts)) transactions = block_given? ? yield(results.transactions) : results.transactions error_citations = transactions.map do |posting| format '%<date>s: %<payee>s', date: posting.date.to_s, payee: posting.payee end error! with_error_msg, error_citations unless error_citations.empty? end |