lib/reckon/app.rb in reckon-0.6.0 vs lib/reckon/app.rb in reckon-0.6.1
- old
+ new
@@ -6,13 +6,14 @@
module Reckon
class App
attr_accessor :options, :seen, :csv_parser, :regexps, :matcher
@@cli = HighLine.new
- def initialize(options = {})
+ def initialize(opts = {})
+ self.options = opts
LOGGER.level = Logger::INFO if options[:verbose]
- self.options = options
+
self.regexps = {}
self.seen = Set.new
self.options[:currency] ||= '$'
@csv_parser = CSVParser.new( options )
@matcher = CosineSimilarity.new(options)
@@ -155,11 +156,11 @@
:pretty_money => @csv_parser.pretty_money_for(index),
:pretty_money_negated => @csv_parser.pretty_money_for(index, :negate),
:money => @csv_parser.money_for(index),
:description => @csv_parser.description_for(index) }
end
- rows.sort_by { |n| n[:date] }.each { |row| yield row }
+ rows.sort_by { |n| [n[:date], -n[:money], n[:description]] }.each { |row| yield row }
end
def print_transaction(rows)
str = "\n"
header = %w[Date Amount Description Note]
@@ -250,11 +251,11 @@
most_specific_regexp_match(row) +
@matcher.find_similar(row[:description]).map { |n| n[:account] }
end
def ledger_format(row, line1, line2)
- out = "#{row[:pretty_date]}\t#{row[:description]}\t; #{row[:note]}\n"
+ out = "#{row[:pretty_date]}\t#{row[:description]}#{row[:note] ? "\t; " + row[:note]: ""}\n"
out += "\t#{line1.first}\t\t\t#{line1.last}\n"
out += "\t#{line2.first}\t\t\t#{line2.last}\n\n"
out
end
@@ -325,10 +326,14 @@
opts.on("", "--money-column 2", Integer, "Specify the money column instead of letting Reckon guess - the first column is column 1") do |column_number|
options[:money_column] = column_number
end
+ opts.on("", "--raw-money", "Don't format money column (for stocks)") do |n|
+ options[:raw] = n
+ end
+
opts.on("", "--date-column 3", Integer, "Specify the date column instead of letting Reckon guess - the first column is column 1") do |column_number|
options[:date_column] = column_number
end
opts.on("", "--contains-header [N]", "The first row of the CSV is a header and should be skipped. Optionally add the number of rows to skip.") do |contains_header|
@@ -397,10 +402,10 @@
exit
end
end
unless options[:bank_account]
- fail "Please specify --account for the unattended mode" if options[:unattended]
+ fail "Please specify --account in unattended mode" if options[:unattended]
options[:bank_account] = @@cli.ask("What is the account name of this bank account in Ledger? ") do |q|
q.readline = true
q.validate = /^.{2,}$/
q.default = "Assets:Bank:Checking"