Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.config
.yardoc
Gemfile.lock
vendor/bundle
InstalledFiles
_yardoc
coverage
Expand Down
2 changes: 1 addition & 1 deletion lib/monetize/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion spec/monetize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down