Skip to content

Commit 6a63723

Browse files
feature: Add support for ETH currency in Money library
1 parent 73b84b5 commit 6a63723

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Dave Kroondyk
3030
Diego Aguir Selzlein
3131
Doug Droper
3232
Douglas Miller
33+
Douglas Suptitz Franca
3334
Ed Saunders
3435
Edwin Vlieg
3536
Eloy

config/currency_non_iso.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,20 @@
142142
"thousands_separator": ",",
143143
"iso_numeric": "",
144144
"smallest_denomination": 1
145+
},
146+
"eth": {
147+
"priority": 100,
148+
"iso_code": "ETH",
149+
"name": "Ethereum",
150+
"symbol": "Ξ",
151+
"alternate_symbols": [],
152+
"subunit": "Wei",
153+
"subunit_to_unit": 100000000,
154+
"symbol_first": true,
155+
"html_entity": "Ξ",
156+
"decimal_mark": ".",
157+
"thousands_separator": ",",
158+
"iso_numeric": "",
159+
"smallest_denomination": 1
145160
}
146161
}

spec/currency_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ def to_s
336336

337337
it "returns false if the currency is not iso" do
338338
expect(described_class.new(:btc).iso?).to be false
339+
expect(described_class.new(:eth).iso?).to be false
339340
end
340341
end
341342

spec/money/formatting_spec.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -914,23 +914,27 @@
914914
end
915915

916916
describe ":drop_trailing_zeros option" do
917+
currencies = ["BTC", "BCH", "ETH"]
918+
917919
specify "(drop_trailing_zeros: true) works as documented" do
918-
expect(Money.new(89000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "0.00089"
919-
expect(Money.new(89000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "0.00089"
920-
expect(Money.new(100089000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "1.00089"
921-
expect(Money.new(100089000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "1.00089"
922-
expect(Money.new(100000000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "1"
923-
expect(Money.new(100000000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "1"
920+
amounts = { 89000 => "0.00089", 100089000 => "1.00089", 100000000 => "1" }
921+
922+
currencies.each do |currency|
923+
amounts.each do |amount, expect|
924+
expect(Money.new(amount, currency).format(drop_trailing_zeros: true, symbol: false)).to eq expect
925+
end
926+
end
924927
expect(Money.new(110, "AUD").format(drop_trailing_zeros: true, symbol: false)).to eq "1.1"
925928
end
926929

927930
specify "(drop_trailing_zeros: false) works as documented" do
928-
expect(Money.new(89000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "0.00089000"
929-
expect(Money.new(89000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "0.00089000"
930-
expect(Money.new(100089000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00089000"
931-
expect(Money.new(100089000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00089000"
932-
expect(Money.new(100000000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00000000"
933-
expect(Money.new(100000000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00000000"
931+
amounts = { 89000 => "0.00089000", 100089000 => "1.00089000", 100000000 => "1.00000000"}
932+
933+
currencies.each do |currency|
934+
amounts.each do |amount, expect|
935+
expect(Money.new(amount, currency).format(drop_trailing_zeros: false, symbol: false)).to eq expect
936+
end
937+
end
934938
expect(Money.new(110, "AUD").format(drop_trailing_zeros: false, symbol: false)).to eq "1.10"
935939
end
936940
end

0 commit comments

Comments
 (0)