mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 23:59:40 +02:00
Add Money and Money Series (#505)
* Add Money class * Standardize creation of money series * Formatting * Fix test
This commit is contained in:
parent
89ea12e9a1
commit
0fe9b6d34a
16 changed files with 228 additions and 161 deletions
|
@ -1,18 +1,18 @@
|
|||
default_currency_options = { unit: "$", precision: 2, delimiter: ",", separator: "." }
|
||||
default_currency_options = { symbol: "$", precision: 2, delimiter: ",", separator: "." }
|
||||
|
||||
CURRENCY_OPTIONS = Hash.new { |hash, key| hash[key] = default_currency_options.dup }.merge(
|
||||
"USD": { unit: "$", precision: 2, delimiter: ",", separator: "." },
|
||||
"EUR": { unit: "€", precision: 2, delimiter: ".", separator: "," },
|
||||
"GBP": { unit: "£", precision: 2, delimiter: ",", separator: "." },
|
||||
"CAD": { unit: "C$", precision: 2, delimiter: ",", separator: "." },
|
||||
"MXN": { unit: "MX$", precision: 2, delimiter: ",", separator: "." },
|
||||
"HKD": { unit: "HK$", precision: 2, delimiter: ",", separator: "." },
|
||||
"CHF": { unit: "CHF", precision: 2, delimiter: ".", separator: "," },
|
||||
"SGD": { unit: "S$", precision: 2, delimiter: ",", separator: "." },
|
||||
"NZD": { unit: "NZ$", precision: 2, delimiter: ",", separator: "." },
|
||||
"AUD": { unit: "A$", precision: 2, delimiter: ",", separator: "." },
|
||||
"KRW": { unit: "₩", precision: 0, delimiter: ",", separator: "." },
|
||||
"INR": { unit: "₹", precision: 2, delimiter: ",", separator: "." }
|
||||
"USD": { symbol: "$", precision: 2, delimiter: ",", separator: "." },
|
||||
"EUR": { symbol: "€", precision: 2, delimiter: ".", separator: "," },
|
||||
"GBP": { symbol: "£", precision: 2, delimiter: ",", separator: "." },
|
||||
"CAD": { symbol: "C$", precision: 2, delimiter: ",", separator: "." },
|
||||
"MXN": { symbol: "MX$", precision: 2, delimiter: ",", separator: "." },
|
||||
"HKD": { symbol: "HK$", precision: 2, delimiter: ",", separator: "." },
|
||||
"CHF": { symbol: "CHF", precision: 2, delimiter: ".", separator: "," },
|
||||
"SGD": { symbol: "S$", precision: 2, delimiter: ",", separator: "." },
|
||||
"NZD": { symbol: "NZ$", precision: 2, delimiter: ",", separator: "." },
|
||||
"AUD": { symbol: "A$", precision: 2, delimiter: ",", separator: "." },
|
||||
"KRW": { symbol: "₩", precision: 0, delimiter: ",", separator: "." },
|
||||
"INR": { symbol: "₹", precision: 2, delimiter: ",", separator: "." }
|
||||
)
|
||||
|
||||
EXCHANGE_RATE_ENABLED = ENV["OPEN_EXCHANGE_APP_ID"].present?
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
class Numeric
|
||||
def cents(precision: 2)
|
||||
return "" unless precision.positive?
|
||||
|
||||
cents = self.to_s.split(".")[1]
|
||||
cents = "" unless cents.to_i.positive?
|
||||
|
||||
zero_padded_cents = cents.ljust(precision, "0")
|
||||
zero_padded_cents[0..precision - 1]
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
class String
|
||||
def unit
|
||||
CURRENCY_OPTIONS[self.to_sym][:unit]
|
||||
end
|
||||
|
||||
def separator
|
||||
CURRENCY_OPTIONS[self.to_sym][:separator]
|
||||
end
|
||||
|
||||
def precision
|
||||
CURRENCY_OPTIONS[self.to_sym][:precision]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue