From a9af12cc3e11e5713e5aee38cfed55298d435182 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Sat, 17 Jan 2026 14:41:21 +0100 Subject: [PATCH 1/2] Parse currencies not in CURRENCY_SYMBOLS --- .gitignore | 1 + lib/monetize/parser.rb | 2 +- spec/monetize_spec.rb | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2e57a9e2c..22ff4cf74 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .config .yardoc Gemfile.lock +vendor/bundle InstalledFiles _yardoc coverage diff --git a/lib/monetize/parser.rb b/lib/monetize/parser.rb index a91810c2c..02a6b328f 100644 --- a/lib/monetize/parser.rb +++ b/lib/monetize/parser.rb @@ -75,7 +75,7 @@ def to_big_decimal(value) def parse_currency computed_currency = nil computed_currency = input[/[A-Z]{2,3}/] - computed_currency = nil unless Monetize::Parser::CURRENCY_SYMBOLS.value?(computed_currency) + computed_currency = nil unless Money::Currency.find(computed_currency) computed_currency ||= compute_currency if assume_from_symbol? found = computed_currency || fallback_currency || Money.default_currency diff --git a/spec/monetize_spec.rb b/spec/monetize_spec.rb index f71779387..de7c597c4 100644 --- a/spec/monetize_spec.rb +++ b/spec/monetize_spec.rb @@ -118,6 +118,7 @@ it 'should use provided currency over symbol' do expect(Monetize.parse('$1.05 CAD')).to eq Money.new(105, 'CAD') + expect(Monetize.parse('$1.05 DKK')).to eq Money.new(105, 'DKK') end it 'ignores ZAR symbols that is part of a text' do @@ -164,12 +165,17 @@ end context 'ISO code' do - it 'parses currency given as ISO code' do + it 'parses currency in CURRENCY_SYMBOLS given as ISO code' do expect('20.00 USD'.to_money).to eq Money.new(20_00, 'USD') expect('20.00 EUR'.to_money).to eq Money.new(20_00, 'EUR') expect('20.00 GBP'.to_money).to eq Money.new(20_00, 'GBP') end + it 'parses currency not in CURRENCY_SYMBOLS given as ISO code' do + expect(Monetize::Parser::CURRENCY_SYMBOLS).to_not have_value('DKK') + expect('20.00 DKK'.to_money).to eq Money.new(20_00, 'DKK') + end + context 'with default currency' do before do Money.default_currency = Money::Currency.new('USD') From a5918772e66658c35688981833f5a732fb99d8ba Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Sat, 17 Jan 2026 21:32:16 +0100 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b537728..b21b25123 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- Fix parsing of ISO codes not in `Monetize::Parser::CURRENCY_SYMBOLS`. ## 2.0.0 - **Breaking change**: Remove deprecated `Monetize.extract_cents`.