Class: HledgerForecast::Transaction
- Inherits:
-
Struct
- Object
- Struct
- HledgerForecast::Transaction
- Defined in:
- lib/hledger_forecast/transaction.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#category ⇒ Object
Returns the value of attribute category.
-
#description ⇒ Object
Returns the value of attribute description.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#from ⇒ Object
Returns the value of attribute from.
-
#roll_up ⇒ Object
Returns the value of attribute roll_up.
-
#summary_exclude ⇒ Object
Returns the value of attribute summary_exclude.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#to ⇒ Object
Returns the value of attribute to.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def account @account end |
#amount ⇒ Object
Returns the value of attribute amount
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def amount @amount end |
#category ⇒ Object
Returns the value of attribute category
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def category @category end |
#description ⇒ Object
Returns the value of attribute description
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def description @description end |
#frequency ⇒ Object
Returns the value of attribute frequency
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def frequency @frequency end |
#from ⇒ Object
Returns the value of attribute from
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def from @from end |
#roll_up ⇒ Object
Returns the value of attribute roll_up
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def roll_up @roll_up end |
#summary_exclude ⇒ Object
Returns the value of attribute summary_exclude
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def summary_exclude @summary_exclude end |
#tags ⇒ Object
Returns the value of attribute tags
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def @tags end |
#to ⇒ Object
Returns the value of attribute to
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def to @to end |
#type ⇒ Object
Returns the value of attribute type
12 13 14 |
# File 'lib/hledger_forecast/transaction.rb', line 12 def type @type end |
Class Method Details
.from_row(row) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hledger_forecast/transaction.rb', line 26 def self.from_row(row) validate_required_fields!(row) from = Calculator.evaluate_from_date(row[:from]) new( type: row[:type], frequency: row[:frequency], account: row[:account], from: from, to: row[:to] ? Calculator.evaluate_date(from, row[:to]) : nil, description: row[:description], category: row[:category], amount: Calculator.evaluate(row[:amount]), roll_up: row[:roll_up], summary_exclude: row[:summary_exclude], tags: row[:tag].to_s.split("|").map(&:strip).reject(&:empty?) ) end |
.validate_required_fields!(row) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/hledger_forecast/transaction.rb', line 70 def self.validate_required_fields!(row) %i[type account from category amount].each do |field| next unless row[field].nil? || row[field].to_s.strip.empty? hint = row[:description] ? " (description: '#{row[:description]}')" : "" raise ArgumentError, "missing required field '#{field}'#{hint}" end end |
Instance Method Details
#annualised_amount ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hledger_forecast/transaction.rb', line 57 def annualised_amount if roll_up amount * roll_up else amount * ANNUAL_MULTIPLIERS.fetch(type) { raise(KeyError, "Unknown type '#{type}'. Set a roll-up for custom transactions.") } end end |
#matches_tags?(filter_tags) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hledger_forecast/transaction.rb', line 45 def () return true if .nil? || .empty? = .select { |t| t.start_with?("-") }.map { |t| t[1..] } = .reject { |t| t.start_with?("-") } return false if .any? && ( & ).any? return ( & ).any? if .any? true end |
#summary_exclude? ⇒ Boolean
68 |
# File 'lib/hledger_forecast/transaction.rb', line 68 def summary_exclude? = !!summary_exclude |