Class: TotalRecall::Ledger

Inherits:
Mustache
  • Object
show all
Defined in:
lib/total_recall.rb

Overview

/ParseStrategy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(, transactions, options={})
  @options = {:max_account_width => 80, :decimal_mark => ','}.merge(options)
  @default_account = 
  @_transactions = transactions
end

Instance Attribute Details

#default_accountObject (readonly)

Returns the value of attribute default_account.



90
91
92
# File 'lib/total_recall.rb', line 90

def 
  @default_account
end

#optionsObject (readonly)

Returns the value of attribute options.



90
91
92
# File 'lib/total_recall.rb', line 90

def options
  @options
end

Class Method Details

.templateObject



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

#transactionsObject



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 ? [, i[:account]] : [i[:account], ])
      if i[:tags].any?
        tagsline = "\n  ; :%s:" % (i[:tags] * ':')
        tagskey = i[:amount] > 0 ? :from_tags : :to_tags
        res[tagskey] = tagsline
      end
      res[:amount] = fmt_amount(i[:amount].abs)
      res[:description], res[:date], res[:currency] = i[:description], i[:date], i[:currency]
      res[:spacer] = " " * (options[:max_account_width] - res[:to].size)
      res
    end
  end
end