Skip to content

Commit a1dae78

Browse files
authored
Merge pull request #197 from c960657/parse-dkk
Parse currencies not in CURRENCY_SYMBOLS
2 parents dcd4f95 + a591877 commit a1dae78

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.config
55
.yardoc
66
Gemfile.lock
7+
vendor/bundle
78
InstalledFiles
89
_yardoc
910
coverage

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Fix parsing of ISO codes not in `Monetize::Parser::CURRENCY_SYMBOLS`.
45

56
## 2.0.0
67
- **Breaking change**: Remove deprecated `Monetize.extract_cents`.

lib/monetize/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def to_big_decimal(value)
7575
def parse_currency
7676
computed_currency = nil
7777
computed_currency = input[/[A-Z]{2,3}/]
78-
computed_currency = nil unless Monetize::Parser::CURRENCY_SYMBOLS.value?(computed_currency)
78+
computed_currency = nil unless Money::Currency.find(computed_currency)
7979
computed_currency ||= compute_currency if assume_from_symbol?
8080

8181
found = computed_currency || fallback_currency || Money.default_currency

spec/monetize_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118

119119
it 'should use provided currency over symbol' do
120120
expect(Monetize.parse('$1.05 CAD')).to eq Money.new(105, 'CAD')
121+
expect(Monetize.parse('$1.05 DKK')).to eq Money.new(105, 'DKK')
121122
end
122123

123124
it 'ignores ZAR symbols that is part of a text' do
@@ -164,12 +165,17 @@
164165
end
165166

166167
context 'ISO code' do
167-
it 'parses currency given as ISO code' do
168+
it 'parses currency in CURRENCY_SYMBOLS given as ISO code' do
168169
expect('20.00 USD'.to_money).to eq Money.new(20_00, 'USD')
169170
expect('20.00 EUR'.to_money).to eq Money.new(20_00, 'EUR')
170171
expect('20.00 GBP'.to_money).to eq Money.new(20_00, 'GBP')
171172
end
172173

174+
it 'parses currency not in CURRENCY_SYMBOLS given as ISO code' do
175+
expect(Monetize::Parser::CURRENCY_SYMBOLS).to_not have_value('DKK')
176+
expect('20.00 DKK'.to_money).to eq Money.new(20_00, 'DKK')
177+
end
178+
173179
context 'with default currency' do
174180
before do
175181
Money.default_currency = Money::Currency.new('USD')

0 commit comments

Comments
 (0)