-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated the sources to allow for custom curreny #11
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,15 @@ def initialize(options = {}) | |
self.tokens = {} | ||
self.accounts = {} | ||
self.seen = {} | ||
|
||
unless options[:currency] | ||
options[:currency] = '$' | ||
end | ||
|
||
unless options[:suffixed] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably not needed since |
||
options[:suffixed] = false | ||
end | ||
|
||
learn! | ||
parse | ||
filter_csv | ||
|
@@ -168,7 +177,12 @@ def pretty_money_for(index, negate = false) | |
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) | ||
|
@@ -403,6 +417,14 @@ def self.parse_opts(args = ARGV) | |
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ def balance(accounts) | |
|
||
def clean_money(money) | ||
return nil if money.nil? || money.length == 0 | ||
money.gsub(/[\$,]/, '').to_f | ||
money.gsub(/[^0-9.-]/, '').to_f | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm.. I based that on this test irb(main):005:0> money = "10.0 SEK"
=> "10.0 SEK"
irb(main):006:0> money.gsub(/[^0-9-]/, '').to_f
=> 100.0
money.gsub(/[^0-9.-]/, '').to_f
=> 10.0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, looks good. :) On Tue, Jun 25, 2013 at 10:15 PM, Sebastian Hörberg <
|
||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
unless
/end
block could be written as: