Skip to content

Commit

Permalink
Correctly parse inputs with currency symbol after the amount (#131)
Browse files Browse the repository at this point in the history
* Correctly parse inputs with currency symbol after the amount

* Fix jruby in TravisCI
  • Loading branch information
antstorm committed Nov 27, 2019
1 parent c97fdd8 commit 8bfb079
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
sudo: false
language: ruby
language:
- ruby
- java
rvm:
- 1.9.3
- 2.0.0
Expand All @@ -10,6 +12,7 @@ rvm:
- 2.5.5
- 2.6.3
- jruby-9.0.5.0
jdk: openjdk8
before_install:
- gem install bundler --version '~> 1.17'
script: bundle exec rspec spec
Expand Down
2 changes: 1 addition & 1 deletion lib/monetize/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def split_major_minor(num, delimiter)
end

def currency_symbol_regex
/\A[\+|\-]?(?<symbol>#{regex_safe_symbols})/
/(?<symbol>#{regex_safe_symbols})/
end
end
end
4 changes: 4 additions & 0 deletions spec/monetize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
expect(Monetize.parse("#{symbol}#{amount_in_units}")).to eq Money.new(amount, iso_code)
end

it "parses formatted inputs with #{iso_code} symbol is after the amount" do
expect(Monetize.parse("#{amount_in_units}#{symbol}")).to eq Money.new(amount, iso_code)
end

context 'prefix' do
it 'parses formatted inputs with plus sign and currency as a symbol' do
expect(Monetize.parse("+#{symbol}#{amount_in_units}")).to eq Money.new(amount, iso_code)
Expand Down

0 comments on commit 8bfb079

Please sign in to comment.