Class: TotalRecall::Ledger
- Inherits:
-
Mustache
- Object
- Mustache
- TotalRecall::Ledger
- Defined in:
- lib/total_recall.rb
Overview
/ParseStrategy
Instance Attribute Summary collapse
-
#default_account ⇒ Object
readonly
Returns the value of attribute default_account.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(default_account, transactions, options = {}) ⇒ Ledger
constructor
A new instance of Ledger.
- #transactions ⇒ Object
Constructor Details
#initialize(default_account, transactions, options = {}) ⇒ Ledger
Returns a new instance of Ledger.
92 93 94 95 96 |
# File 'lib/total_recall.rb', line 92 def initialize(default_account, transactions, ={}) @options = {:max_account_width => 80, :decimal_mark => ','}.merge() @default_account = default_account @_transactions = transactions end |
Instance Attribute Details
#default_account ⇒ Object (readonly)
Returns the value of attribute default_account.
90 91 92 |
# File 'lib/total_recall.rb', line 90 def default_account @default_account end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
90 91 92 |
# File 'lib/total_recall.rb', line 90 def @options end |
Class Method Details
.template ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/total_recall.rb', line 117 def self.template;<<-TEMPLATE {{# transactions}} {{date}} {{description}} {{to}} {{spacer}}{{currency}} {{amount}}{{to_tags}} {{from}}{{from_tags}} {{/ transactions}} TEMPLATE end |
Instance Method Details
#transactions ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/total_recall.rb', line 98 def transactions @transactions ||= begin @_transactions.map do |i| res = {} res[:to], res[:from] = (i[:amount] > 0 ? [default_account, i[:account]] : [i[:account], default_account]) if i[:tags].any? = "\n ; :%s:" % (i[:tags] * ':') = i[:amount] > 0 ? :from_tags : :to_tags res[] = end res[:amount] = fmt_amount(i[:amount].abs) res[:description], res[:date], res[:currency] = i[:description], i[:date], i[:currency] res[:spacer] = " " * ([:max_account_width] - res[:to].size) res end end end |