lib/reckon/app.rb in reckon-0.3.6 vs lib/reckon/app.rb in reckon-0.3.7
- old
+ new
@@ -8,10 +8,11 @@
def initialize(options = {})
self.options = options
self.tokens = {}
self.accounts = {}
self.seen = {}
+ self.options[:currency] ||= '$'
learn!
parse
filter_csv
detect_columns
end
@@ -166,11 +167,16 @@
def pretty_money_for(index, negate = false)
pretty_money(money_for(index), negate)
end
def pretty_money(amount, negate = false)
- (amount >= 0 ? " " : "") + sprintf("%0.2f", amount * (negate ? -1 : 1)).gsub(/^((\-)|)(?=\d)/, '\1$')
+ currency = options[:currency]
+ if options[:suffixed]
+ (amount >= 0 ? " " : "") + sprintf("%0.2f #{currency}", amount * (negate ? -1 : 1))
+ else
+ (amount >= 0 ? " " : "") + sprintf("%0.2f", amount * (negate ? -1 : 1)).gsub(/^((\-)|)(?=\d)/, "\\1#{currency}")
+ end
end
def date_for(index)
value = columns[date_column_index][index]
value = [$1, $2, $3].join("/") if value =~ /^(\d{4})(\d{2})(\d{2})\d+\[\d+\:GMT\]$/ # chase format
@@ -357,10 +363,14 @@
opts.on("-f", "--file FILE", "The CSV file to parse") do |file|
options[:file] = file
end
+ opts.on("-a", "--account name", "The Ledger Account this file is for") do |a|
+ options[:bank_account] = a
+ end
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
opts.on("-i", "--inverse", "Use the negative of each amount") do |v|
@@ -395,9 +405,17 @@
options[:comma_separates_cents] = c
end
opts.on("", "--encoding", "Specify an encoding for the CSV file") do |e|
options[:encoding] = e
+ end
+
+ opts.on("-c", "--currency", "Currency symbol to use, defaults to $. ex.) $, EUR") do |e|
+ options[:currency] = e
+ end
+
+ opts.on("", "--suffixed", "If --currency should be used as a suffix. Defaults to false.") do |e|
+ options[:suffixed] = e
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit