money_helper 0.0.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.circleci/config.yml +47 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +21 -0
- data/.rubocop_todo.yml +12 -0
- data/Appraisals +29 -0
- data/CHANGELOG.md +49 -0
- data/Gemfile +5 -0
- data/LICENSE.md +20 -0
- data/README.md +49 -0
- data/RELEASING.md +65 -0
- data/Rakefile +17 -0
- data/gemfiles/activesupport_40.gemfile +8 -0
- data/gemfiles/activesupport_41.gemfile +8 -0
- data/gemfiles/activesupport_42.gemfile +8 -0
- data/gemfiles/activesupport_50.gemfile +8 -0
- data/gemfiles/activesupport_51.gemfile +8 -0
- data/gemfiles/activesupport_52.gemfile +8 -0
- data/gemfiles/activesupport_edge.gemfile +11 -0
- data/lib/money_helper.rb +60 -38
- data/lib/version.rb +3 -0
- data/money_helper.gemspec +22 -0
- data/spec/money_helper_spec.rb +223 -164
- data/spec/spec_helper.rb +6 -0
- data/spec/version_spec.rb +7 -0
- metadata +65 -26
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZWRhNjgyOTJiN2ViZjdkMTExMDkwZGJmYTU2ZTI4NDc1NjY0NzczMQ==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: df602a2214fc58f6ccf9041f9cce6cc87ba22609f6d8314b6a497b5802de48ff
|
4
|
+
data.tar.gz: 46e3888d004f525559bf11b657e7cb504eb9c12f5dcaed61a56b18f1469a1e64
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
Yzg5YTdkZjA2YjY1NGMwODNmYTIzMDIyOGRmNDdmMDMxNTBiZWNiNWNjYmVi
|
11
|
-
N2MyNjNlZThlYTEzOGQxOTg3MDAxNWI0N2Q5NjQwNWU1MGZhOTQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MjUyMTE5NzY0MjA1NWY3MDVhNmYwNDk5NDg4YzRkZTBjMTgxOGE2MmIyOGUx
|
14
|
-
NzNhMWZmNmJkOTEzZTc2MTViOTBlNmMzMmYxMjJmYTQ0NTc1NDRkZTYwODc1
|
15
|
-
M2M5MWU1ZmExYTllMmQ2YzlhNDU1MGIwNDIyZWQxNDkzZWRmM2M=
|
6
|
+
metadata.gz: 1b5f70766be6b1091e40266cb5c3cbcb34d0457e37511e60537935bc4408dada70693d0141e3c95840894f3a3d34658a99cd1354c413b58c97484047448dcecc
|
7
|
+
data.tar.gz: 7eb7051305203fed98bed96d14c2651c989fc498c58859802a85bdd26e7dda11792cef78ad9c0290530b3cd7bd69d4c94c2664cfc0bb4f487584c68e86016e25
|
@@ -0,0 +1,47 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
references:
|
4
|
+
set_env: &set_env
|
5
|
+
run:
|
6
|
+
name: Set up environment
|
7
|
+
command: |
|
8
|
+
echo "export BUNDLE_GEMFILE=$(pwd)/gemfiles/activesupport_$ACTIVESUPPORT_VERSION.gemfile" >> $BASH_ENV
|
9
|
+
bundle: &bundle
|
10
|
+
run:
|
11
|
+
name: Install dependencies
|
12
|
+
command: bundle install
|
13
|
+
test: &test
|
14
|
+
run:
|
15
|
+
name: Run test suite
|
16
|
+
command: bundle exec rake
|
17
|
+
|
18
|
+
jobs:
|
19
|
+
test:
|
20
|
+
docker:
|
21
|
+
- image: "cimg/ruby:<< parameters.ruby_version >>"
|
22
|
+
parameters:
|
23
|
+
ruby_version:
|
24
|
+
type: string
|
25
|
+
activesupport_version:
|
26
|
+
type: string
|
27
|
+
environment:
|
28
|
+
ACTIVESUPPORT_VERSION: << parameters.activesupport_version >>
|
29
|
+
steps:
|
30
|
+
- checkout
|
31
|
+
- <<: *set_env
|
32
|
+
- <<: *bundle
|
33
|
+
- <<: *test
|
34
|
+
|
35
|
+
workflows:
|
36
|
+
default:
|
37
|
+
jobs:
|
38
|
+
- test:
|
39
|
+
matrix:
|
40
|
+
parameters:
|
41
|
+
ruby_version: ["2.5", "2.6", "2.7"]
|
42
|
+
activesupport_version: ["40", "41", "42", "50", "51", "52", "edge"]
|
43
|
+
exclude:
|
44
|
+
- ruby_version: "2.5"
|
45
|
+
activesupport_version: "edge"
|
46
|
+
- ruby_version: "2.6"
|
47
|
+
activesupport_version: "edge"
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- vendor/**/*
|
4
|
+
- gemfiles/vendor/**/*
|
5
|
+
|
6
|
+
Metrics:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 512
|
11
|
+
|
12
|
+
Style/Documentation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Naming/MethodName:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/AsciiComments:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2019-04-19 14:01:54 -0400 using RuboCop version 0.67.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 3
|
10
|
+
Lint/IneffectiveAccessModifier:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/money_helper.rb'
|
data/Appraisals
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
appraise 'activesupport_40' do
|
2
|
+
gem 'activesupport', '~> 4.0.0'
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise 'activesupport_41' do
|
6
|
+
gem 'activesupport', '~> 4.1.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'activesupport_42' do
|
10
|
+
gem 'activesupport', '~> 4.2.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'activesupport_50' do
|
14
|
+
gem 'activesupport', '~> 5.0.0'
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise 'activesupport_51' do
|
18
|
+
gem 'activesupport', '~> 5.1.0'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise 'activesupport_52' do
|
22
|
+
gem 'activesupport', '~> 5.2.1'
|
23
|
+
end
|
24
|
+
|
25
|
+
appraise 'activesupport_edge' do
|
26
|
+
git 'git://github.com/rails/rails.git' do
|
27
|
+
gem 'activesupport', require: 'active_support'
|
28
|
+
end
|
29
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
### 2.0.1 (Next)
|
2
|
+
|
3
|
+
* Your contribution here.
|
4
|
+
|
5
|
+
### 2.0.0 (2021-09-20)
|
6
|
+
|
7
|
+
#### Breaking Changes
|
8
|
+
|
9
|
+
* [#20](https://github.com/artsy/money_helper/pull/20): Update `money_to_text` and `money_range_to_text` to expect amounts in minor unit and simplify formatting; drop support for Ruby 2.3 and 2.4 - [@starsirius](https://github.com/starsirius)
|
10
|
+
|
11
|
+
### 1.0.2 (2019-04-19)
|
12
|
+
|
13
|
+
* [#16](https://github.com/artsy/money_helper/pull/16): Remove deprecation warnings - [@sweir27](https://github.com/sweir27).
|
14
|
+
* [#15](https://github.com/artsy/money_helper/pull/15): Added Rubocop - [@dblock](https://github.com/dblock).
|
15
|
+
|
16
|
+
### 1.0.1 (2017-04-03)
|
17
|
+
|
18
|
+
* Relaxed activesupport version dependency - [@dblock](https://github.com/dblock).
|
19
|
+
* The `money_to_text` method now takes options - [@mzikherman](https://github.com/mzikherman).
|
20
|
+
* Added `symbol_with_optional_iso_code` - [@mzikherman](https://github.com/mzikherman).
|
21
|
+
|
22
|
+
### 1.0.0 (2015-03-07)
|
23
|
+
|
24
|
+
* Added compatibility with Money 6.5.1+, including new currency symbols - [@syakhmi](https://github.com/syakhmi).
|
25
|
+
|
26
|
+
### 0.0.5 (2014-04-12)
|
27
|
+
|
28
|
+
* Added compatibility with Money 6.1+ - [@syakhmi](https://github.com/syakhmi).
|
29
|
+
* Dropped support for pre 6.0 versions of Money - [@syakhmi](https://github.com/syakhmi).
|
30
|
+
|
31
|
+
### 0.0.4 (2014-01-08)
|
32
|
+
|
33
|
+
* Added compatibility with Money 6.x - [@dblock](https://github.com/dblock).
|
34
|
+
* Avoid failing on deprecated currencies (such as ITL) - [@joeyAghion](https://github.com/joeyAghion).
|
35
|
+
|
36
|
+
### 0.0.3 (2013-07-17)
|
37
|
+
|
38
|
+
* Added support for currencies that don't have a symbol, eg. Uzbekistan Som (UZS) - [@dblock](https://github.com/dblock).
|
39
|
+
|
40
|
+
### 0.0.2 (2013-07-16)
|
41
|
+
|
42
|
+
* Added unit tests - [@syakhmi](https://github.com/syakhmi).
|
43
|
+
* Added support for Cambodian riel - [@syakhmi](https://github.com/syakhmi).
|
44
|
+
* Added dependencies to gemspec - [@syakhmi](https://github.com/syakhmi).
|
45
|
+
* Now defaults to USD when currency not specified - [@syakhmi](https://github.com/syakhmi).
|
46
|
+
|
47
|
+
### 0.0.1 (2013-07-12)
|
48
|
+
|
49
|
+
* Initial public release - [@syakhmi](https://github.com/syakhmi).
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013-2018 Artsy, Sahil Yakhmi, Joey Aghion, and contributors.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
MoneyHelper [![CircleCI][ci_badge]][circleci]
|
2
|
+
============
|
3
|
+
|
4
|
+
A simple module to assist in formatting unambiguous prices and price ranges in international currencies in a Roman Script environment.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
Examples:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
money_to_text(10000, currency: 'AUD')
|
13
|
+
#=> 'AUD $100.00'
|
14
|
+
|
15
|
+
money_to_text(10000, currency: 'AUD', with_currency: false, with_symbol: false)
|
16
|
+
#=> '100.00'
|
17
|
+
|
18
|
+
money_range_to_text(10000, 40000, currency: 'AUD')
|
19
|
+
#=> 'AUD $100.00 - 400.00'
|
20
|
+
|
21
|
+
money_range_to_text(10000, 40000, currency: 'AUD', delimiter: ' ... ')
|
22
|
+
#=> 'AUD $100.00 ... 400.00'
|
23
|
+
```
|
24
|
+
|
25
|
+
Defaults
|
26
|
+
--------
|
27
|
+
|
28
|
+
As of [#16][#16] this library explicitly specifies the `Money.locale_backend = :currency` default.
|
29
|
+
|
30
|
+
Contributing
|
31
|
+
------------
|
32
|
+
|
33
|
+
Fork the project. Make your feature addition or bug fix with tests. Send a pull request.
|
34
|
+
|
35
|
+
Copyright and License
|
36
|
+
---------------------
|
37
|
+
|
38
|
+
MIT License, see [LICENSE][license] for details.
|
39
|
+
|
40
|
+
(c) 2013-2018 [Artsy][artsy], [Sahil Yakhmi][sahil_yakhmi], [Joey Aghion][joey_aghion] and [contributors][contributors].
|
41
|
+
|
42
|
+
[ci_badge]: https://circleci.com/gh/artsy/money_helper/tree/master.svg?style=shield
|
43
|
+
[circleci]: https://circleci.com/gh/artsy/money_helper/tree/master
|
44
|
+
[#16]: https://github.com/artsy/money_helper/pull/16
|
45
|
+
[license]: LICENSE.md
|
46
|
+
[artsy]: https://github.com/artsy
|
47
|
+
[sahil_yakhmi]: https://github.com/syakhmi
|
48
|
+
[joey_aghion]: https://github.com/joeyAghion
|
49
|
+
[contributors]: CHANGELOG.md
|
data/RELEASING.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Releasing money_helper
|
2
|
+
|
3
|
+
There are no hard rules about when to release money_helper. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
4
|
+
|
5
|
+
### Release
|
6
|
+
|
7
|
+
Run tests, check that all tests succeed locally.
|
8
|
+
|
9
|
+
```
|
10
|
+
bundle install
|
11
|
+
rake
|
12
|
+
```
|
13
|
+
|
14
|
+
Check that the last build succeeded on [CI][ci] for all supported platforms.
|
15
|
+
|
16
|
+
Change "Next" in [CHANGELOG.md][changelog] to the current date.
|
17
|
+
|
18
|
+
```
|
19
|
+
### 0.2.2 (2015/7/10)
|
20
|
+
```
|
21
|
+
|
22
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
23
|
+
|
24
|
+
Commit your changes.
|
25
|
+
|
26
|
+
```
|
27
|
+
git add CHANGELOG.md
|
28
|
+
git commit -m "Preparing for release, 0.2.2."
|
29
|
+
git push origin master
|
30
|
+
```
|
31
|
+
|
32
|
+
Release.
|
33
|
+
|
34
|
+
```
|
35
|
+
$ rake release
|
36
|
+
|
37
|
+
money_helper 0.2.2 built to pkg/money_helper-0.2.2.gem.
|
38
|
+
Tagged v0.2.2.
|
39
|
+
Pushed git commits and tags.
|
40
|
+
Pushed money_helper 0.2.2 to rubygems.org.
|
41
|
+
```
|
42
|
+
|
43
|
+
### Prepare for the Next Version
|
44
|
+
|
45
|
+
Add the next release to [CHANGELOG.md][changelog].
|
46
|
+
|
47
|
+
```
|
48
|
+
### 0.2.3 (Next)
|
49
|
+
|
50
|
+
* Your contribution here.
|
51
|
+
```
|
52
|
+
|
53
|
+
Increment the third version number in [lib/version.rb][version].
|
54
|
+
|
55
|
+
Commit your changes.
|
56
|
+
|
57
|
+
```
|
58
|
+
git add CHANGELOG.md lib/version.rb
|
59
|
+
git commit -m "Preparing for next development iteration, 0.2.3."
|
60
|
+
git push origin master
|
61
|
+
```
|
62
|
+
|
63
|
+
[ci]: https://circleci.com/gh/artsy/money_helper/tree/master
|
64
|
+
[changelog]: CHANGELOG.md
|
65
|
+
[version]: lib/version.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
Bundler.setup :default, :development
|
6
|
+
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
11
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rubocop/rake_task'
|
15
|
+
RuboCop::RakeTask.new
|
16
|
+
|
17
|
+
task default: %i[rubocop spec]
|
data/lib/money_helper.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
require_relative 'version'
|
2
2
|
|
3
3
|
require 'active_support/core_ext/object/blank'
|
4
4
|
require 'money'
|
5
5
|
|
6
6
|
module MoneyHelper
|
7
|
+
Money.locale_backend = :currency
|
8
|
+
I18n.enforce_available_locales = false
|
7
9
|
|
8
|
-
SYMBOL_ONLY = %w
|
9
|
-
OK_SYMBOLS = %w
|
10
|
-
$ £ € ¥ 元 р. L ƒ ৳ P R$ K ₡ D ლ ₵ Q G ₹ Rp ₪ ₩ ₭ R RM ₨ ₮ դր. C$ ₦
|
11
|
-
|
10
|
+
SYMBOL_ONLY = %w[USD GBP EUR MYR].freeze # don't use ISO code
|
11
|
+
OK_SYMBOLS = %w[
|
12
|
+
$ £ € ¥ 元 р. L ƒ ৳ P R$ K ₡ D ლ ₵ Q G ₹ Rp ₪ ₩ ₭ R RM ₨ ₮ դր. C$ ₦ ₲ ₱ T ฿ T$ m ₴ ₫ ៛ ₺ E ₽
|
13
|
+
].freeze # ok to include in string
|
12
14
|
|
13
15
|
##
|
14
16
|
# Formats a single amount in the given currency into a price string. Defaults to USD if currency not
|
@@ -16,27 +18,39 @@ module MoneyHelper
|
|
16
18
|
#
|
17
19
|
# = Example
|
18
20
|
#
|
19
|
-
#
|
21
|
+
# MoneyHelper.money_to_text(30_175_93, currency: 'USD') #=> 'USD $30,175.93'
|
22
|
+
# MoneyHelper.money_to_text(30_175_93, currency: 'EUR') #=> 'EUR €30.175,93'
|
23
|
+
# MoneyHelper.money_to_text(30_175_93) #=> 'USD $30,175.93'
|
20
24
|
#
|
21
25
|
# = Arguments
|
22
26
|
#
|
23
|
-
#
|
24
|
-
# currency: (String)
|
25
|
-
#
|
26
|
-
#
|
27
|
-
def self.money_to_text(
|
28
|
-
return
|
29
|
-
|
30
|
-
|
27
|
+
# amount_minor: (Integer) amount in minor unit
|
28
|
+
# currency: (String) optional ISO currency code, defaulting to USD
|
29
|
+
# with_currency: (Boolean) optional flag to include ISO currency code, defaulting to true
|
30
|
+
# with_symbol: (Boolean) optional flag to include currency symbol, defaulting to true
|
31
|
+
def self.money_to_text(amount_minor, currency: 'USD', with_currency: true, with_symbol: true)
|
32
|
+
return '' if amount_minor.blank?
|
33
|
+
|
34
|
+
money_options = {
|
35
|
+
format: '%u%n',
|
36
|
+
symbol: with_symbol
|
37
|
+
}
|
38
|
+
|
39
|
+
formatted_amount = Money.new(amount_minor, currency).format(money_options)
|
40
|
+
formatted_currency = with_currency ? currency.upcase : ''
|
41
|
+
|
42
|
+
"#{formatted_currency} #{formatted_amount}".strip
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.symbol_with_optional_iso_code(currency = 'USD')
|
31
46
|
symbol = symbol_for_code(currency)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}).delete(' ')
|
47
|
+
if SYMBOL_ONLY.include?(currency)
|
48
|
+
symbol
|
49
|
+
elsif symbol && OK_SYMBOLS.include?(symbol)
|
50
|
+
"#{iso_for_currency(currency)} #{symbol}"
|
51
|
+
else
|
52
|
+
iso_for_currency(currency).to_s
|
53
|
+
end
|
40
54
|
end
|
41
55
|
|
42
56
|
##
|
@@ -44,42 +58,50 @@ module MoneyHelper
|
|
44
58
|
#
|
45
59
|
# = Example
|
46
60
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
61
|
+
# MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD') #=> 'USD $30,175.93 - 40,983.27'
|
62
|
+
# MoneyHelper.money_range_to_text(30_175_93, 40_983_27) #=> 'USD $30,175.93 - 40,983.27'
|
63
|
+
# MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'EUR') #=> 'EUR €30.175,93 - 40.983,27'
|
64
|
+
# MoneyHelper.money_range_to_text(30_175_93, 40_983_27, delimiter: ' ... ') #=> 'USD $30,175.93 ... 40,983.27'
|
51
65
|
#
|
52
66
|
# = Arguments
|
53
67
|
#
|
54
|
-
# low: (
|
55
|
-
# high: (
|
56
|
-
# currency: (String)
|
68
|
+
# low: (Integer) amount in minor unit
|
69
|
+
# high: (Integer) amount in minor unit
|
70
|
+
# currency: (String) optional ISO currency code, defaulting to USD
|
57
71
|
# delimiter: (String) optional
|
58
|
-
def self.money_range_to_text(low, high, currency, delimiter
|
72
|
+
def self.money_range_to_text(low, high, currency: 'USD', delimiter: ' - ')
|
59
73
|
if low.blank? && high.blank?
|
60
|
-
|
74
|
+
''
|
61
75
|
elsif low.blank?
|
62
|
-
|
76
|
+
'Under ' + money_to_text(high, currency: currency)
|
63
77
|
elsif high.blank?
|
64
|
-
money_to_text(low, currency) +
|
78
|
+
money_to_text(low, currency: currency) + ' and up'
|
65
79
|
elsif low == high
|
66
|
-
money_to_text(low, currency)
|
80
|
+
money_to_text(low, currency: currency)
|
67
81
|
else
|
68
|
-
|
82
|
+
formatted_low = money_to_text(low, currency: currency)
|
83
|
+
formatted_high = money_to_text(high, currency: currency, with_currency: false, with_symbol: false)
|
84
|
+
[formatted_low, formatted_high].compact.join(delimiter)
|
69
85
|
end
|
70
86
|
end
|
71
87
|
|
72
|
-
private
|
73
|
-
|
74
88
|
def self.code_valid?(code)
|
75
89
|
Money::Currency.stringified_keys.include?(code.downcase)
|
76
90
|
end
|
77
91
|
|
92
|
+
def self.iso_for_currency(code)
|
93
|
+
return unless code && code_valid?(code)
|
94
|
+
|
95
|
+
Money::Currency.new(code).iso_code.tap do |iso_code|
|
96
|
+
iso_code.strip! if iso_code.present?
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
78
100
|
def self.symbol_for_code(code)
|
79
101
|
return unless code && code_valid?(code)
|
102
|
+
|
80
103
|
Money::Currency.new(code).symbol.tap do |symbol|
|
81
104
|
symbol.strip! if symbol.present?
|
82
105
|
end
|
83
106
|
end
|
84
|
-
|
85
107
|
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
|
+
require 'version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'money_helper'
|
6
|
+
s.version = MoneyHelper::VERSION
|
7
|
+
s.summary = 'MoneyHelper international price formatting utility.'
|
8
|
+
s.description = 'A simple module to assist in formatting unambiguous prices and price ranges in international currencies in a Roman Script context.'
|
9
|
+
s.authors = ['Sahil Yakhmi', 'Joey Aghion', 'Matt Zikherman', 'Sarah Weir']
|
10
|
+
s.email = 'matt@artsymail.com'
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.required_rubygems_version = '>= 1.3.6'
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
s.homepage = 'https://github.com/artsy/money_helper'
|
17
|
+
s.add_dependency('activesupport')
|
18
|
+
s.add_dependency('money', '6.16.0')
|
19
|
+
s.add_development_dependency('appraisal')
|
20
|
+
s.add_development_dependency('rspec', '~> 3')
|
21
|
+
s.licenses = ['MIT']
|
22
|
+
end
|
data/spec/money_helper_spec.rb
CHANGED
@@ -1,178 +1,237 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'money_helper'
|
1
|
+
require 'spec_helper'
|
4
2
|
|
5
3
|
describe MoneyHelper do
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
MoneyHelper.money_to_text(
|
9
|
-
MoneyHelper.money_to_text(
|
10
|
-
MoneyHelper.money_to_text(
|
11
|
-
MoneyHelper.money_to_text(
|
12
|
-
MoneyHelper.money_to_text(
|
13
|
-
|
14
|
-
|
15
|
-
MoneyHelper.money_to_text(
|
16
|
-
MoneyHelper.money_to_text(
|
17
|
-
MoneyHelper.money_to_text(
|
18
|
-
MoneyHelper.money_to_text(
|
19
|
-
MoneyHelper.money_to_text(
|
20
|
-
MoneyHelper.money_to_text(
|
21
|
-
MoneyHelper.money_to_text(
|
22
|
-
MoneyHelper.money_to_text(
|
23
|
-
MoneyHelper.money_to_text(
|
24
|
-
MoneyHelper.money_to_text(
|
25
|
-
MoneyHelper.money_to_text(
|
26
|
-
MoneyHelper.money_to_text(
|
27
|
-
MoneyHelper.money_to_text(
|
28
|
-
MoneyHelper.money_to_text(
|
29
|
-
MoneyHelper.money_to_text(
|
30
|
-
MoneyHelper.money_to_text(
|
31
|
-
MoneyHelper.money_to_text(
|
32
|
-
MoneyHelper.money_to_text(
|
33
|
-
MoneyHelper.money_to_text(
|
34
|
-
MoneyHelper.money_to_text(
|
35
|
-
MoneyHelper.money_to_text(
|
36
|
-
MoneyHelper.money_to_text(
|
37
|
-
MoneyHelper.money_to_text(
|
38
|
-
MoneyHelper.money_to_text(
|
39
|
-
|
40
|
-
MoneyHelper.money_to_text(
|
41
|
-
|
42
|
-
MoneyHelper.money_to_text(
|
43
|
-
MoneyHelper.money_to_text(
|
44
|
-
MoneyHelper.money_to_text(
|
45
|
-
|
46
|
-
MoneyHelper.money_to_text(
|
47
|
-
|
48
|
-
MoneyHelper.money_to_text(
|
49
|
-
MoneyHelper.money_to_text(
|
50
|
-
|
51
|
-
MoneyHelper.money_to_text(
|
52
|
-
MoneyHelper.money_to_text(
|
53
|
-
|
54
|
-
MoneyHelper.money_to_text(
|
55
|
-
MoneyHelper.money_to_text(
|
56
|
-
MoneyHelper.money_to_text(
|
57
|
-
MoneyHelper.money_to_text(
|
58
|
-
|
59
|
-
MoneyHelper.money_to_text(
|
60
|
-
|
61
|
-
|
62
|
-
MoneyHelper.money_to_text(
|
63
|
-
|
64
|
-
|
65
|
-
MoneyHelper.money_to_text(
|
66
|
-
|
67
|
-
|
68
|
-
MoneyHelper.money_to_text(
|
69
|
-
|
70
|
-
MoneyHelper.money_to_text(
|
71
|
-
MoneyHelper.money_to_text(
|
72
|
-
|
73
|
-
MoneyHelper.money_to_text(
|
74
|
-
|
75
|
-
|
76
|
-
MoneyHelper.money_to_text(
|
77
|
-
MoneyHelper.money_to_text(
|
78
|
-
MoneyHelper.money_to_text(
|
79
|
-
MoneyHelper.money_to_text(
|
80
|
-
MoneyHelper.money_to_text(
|
81
|
-
MoneyHelper.money_to_text(
|
82
|
-
MoneyHelper.money_to_text(
|
83
|
-
MoneyHelper.money_to_text(
|
84
|
-
MoneyHelper.money_to_text(
|
85
|
-
MoneyHelper.money_to_text(
|
86
|
-
MoneyHelper.money_to_text(
|
87
|
-
MoneyHelper.money_to_text(
|
88
|
-
MoneyHelper.money_to_text(
|
89
|
-
MoneyHelper.money_to_text(
|
90
|
-
MoneyHelper.money_to_text(
|
91
|
-
MoneyHelper.money_to_text(
|
92
|
-
MoneyHelper.money_to_text(
|
93
|
-
MoneyHelper.money_to_text(
|
94
|
-
MoneyHelper.money_to_text(
|
95
|
-
MoneyHelper.money_to_text(
|
96
|
-
MoneyHelper.money_to_text(
|
97
|
-
MoneyHelper.money_to_text(
|
98
|
-
MoneyHelper.money_to_text(
|
99
|
-
MoneyHelper.money_to_text(
|
100
|
-
MoneyHelper.money_to_text(
|
101
|
-
MoneyHelper.money_to_text(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
MoneyHelper.money_to_text(
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
MoneyHelper.money_to_text(
|
111
|
-
MoneyHelper.money_to_text(
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
MoneyHelper.money_to_text(
|
116
|
-
MoneyHelper.money_to_text(
|
117
|
-
MoneyHelper.money_to_text(
|
118
|
-
MoneyHelper.money_to_text(
|
119
|
-
MoneyHelper.money_to_text(
|
120
|
-
MoneyHelper.money_to_text(
|
121
|
-
MoneyHelper.money_to_text(
|
122
|
-
MoneyHelper.money_to_text(
|
123
|
-
MoneyHelper.money_to_text(
|
124
|
-
MoneyHelper.money_to_text(
|
125
|
-
MoneyHelper.money_to_text(
|
126
|
-
MoneyHelper.money_to_text(
|
127
|
-
MoneyHelper.money_to_text(
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
MoneyHelper.money_to_text(
|
137
|
-
MoneyHelper.money_to_text(
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
MoneyHelper.money_to_text(
|
146
|
-
MoneyHelper.money_to_text(
|
4
|
+
describe 'money_to_text' do
|
5
|
+
it 'includes ISO code and symbol' do
|
6
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD')).to eql('AUD $30,175.93')
|
7
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ARS')).to eql('ARS $30.175,93')
|
8
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BBD')).to eql('BBD $30,175.93')
|
9
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BMD')).to eql('BMD $30,175.93')
|
10
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BND')).to eql('BND $30,175.93')
|
11
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BSD')).to eql('BSD $30,175.93')
|
12
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BZD')).to eql('BZD $30,175.93')
|
13
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CAD')).to eql('CAD $30,175.93')
|
14
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CLP')).to eql('CLP $3.017.593')
|
15
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'COP')).to eql('COP $30.175,93')
|
16
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CUC')).to eql('CUC $30,175.93')
|
17
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CUP')).to eql('CUP $30,175.93')
|
18
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'DOP')).to eql('DOP $30,175.93')
|
19
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'FJD')).to eql('FJD $30,175.93')
|
20
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GYD')).to eql('GYD $30,175.93')
|
21
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'HKD')).to eql('HKD $30,175.93')
|
22
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'JMD')).to eql('JMD $30,175.93')
|
23
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'KYD')).to eql('KYD $30,175.93')
|
24
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'LRD')).to eql('LRD $30,175.93')
|
25
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MXN')).to eql('MXN $30,175.93')
|
26
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NAD')).to eql('NAD $30,175.93')
|
27
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NZD')).to eql('NZD $30,175.93')
|
28
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SBD')).to eql('SBD $30,175.93')
|
29
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SGD')).to eql('SGD $30,175.93')
|
30
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SRD')).to eql('SRD $30,175.93')
|
31
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TWD')).to eql('TWD $30,175.93')
|
32
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TTD')).to eql('TTD $30,175.93')
|
33
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'UYU')).to eql('UYU $U30.175,93')
|
34
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
35
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'XCD')).to eql('XCD $30,175.93')
|
36
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ZWL')).to eql('ZWL $30,175.93')
|
37
|
+
|
38
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR')).to eql('EUR €30.175,93')
|
39
|
+
|
40
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'FKP')).to eql('FKP £30,175.93')
|
41
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GBP')).to eql('GBP £30,175.93')
|
42
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GIP')).to eql('GIP £30,175.93')
|
43
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SDG')).to eql('SDG £30,175.93')
|
44
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SHP')).to eql('SHP £30,175.93')
|
45
|
+
|
46
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CNY')).to eql('CNY ¥30,175.93')
|
47
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'JPY')).to eql('JPY ¥3,017,593')
|
48
|
+
|
49
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ALL')).to eql('ALL L30,175.93')
|
50
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'HNL')).to eql('HNL L30,175.93')
|
51
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'LSL')).to eql('LSL L30,175.93')
|
52
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MDL')).to eql('MDL L30,175.93')
|
53
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MYR')).to eql('MYR RM30,175.93')
|
54
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'RON')).to eql('RON Lei30.175,93')
|
55
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SZL')).to eql('SZL E30,175.93')
|
56
|
+
|
57
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ANG')).to eql('ANG ƒ30.175,93')
|
58
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AWG')).to eql('AWG ƒ30,175.93')
|
59
|
+
|
60
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BWP')).to eql('BWP P30,175.93')
|
61
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MOP')).to eql('MOP P30,175.93')
|
62
|
+
|
63
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CRC')).to eql('CRC ₡30.175,93')
|
64
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SVC')).to eql('SVC ₡30,175.93')
|
65
|
+
|
66
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MUR')).to eql('MUR ₨30,175.93')
|
67
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NPR')).to eql('NPR Rs.30,175.93')
|
68
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'PKR')).to eql('PKR ₨30,175.93')
|
69
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SCR')).to eql('SCR ₨30,175.93')
|
70
|
+
|
71
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD')).to eql('AMD դր.30,175.93')
|
72
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BDT')).to eql('BDT ৳30,175.93')
|
73
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BRL')).to eql('BRL R$30.175,93')
|
74
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GEL')).to eql('GEL ლ30,175.93')
|
75
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GHS')).to eql('GHS ₵30,175.93')
|
76
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GMD')).to eql('GMD D30,175.93')
|
77
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GTQ')).to eql('GTQ Q30,175.93')
|
78
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'HTG')).to eql('HTG G30,175.93')
|
79
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'IDR')).to eql('IDR Rp30.175,93')
|
80
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ILS')).to eql('ILS ₪30,175.93')
|
81
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'INR')).to eql('INR ₹30,175.93')
|
82
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'KHR')).to eql('KHR ៛30,175.93')
|
83
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'KPW')).to eql('KPW ₩30,175.93')
|
84
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'LAK')).to eql('LAK ₭30,175.93')
|
85
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MNT')).to eql('MNT ₮30,175.93')
|
86
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NGN')).to eql('NGN ₦30,175.93')
|
87
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NIO')).to eql('NIO C$30,175.93')
|
88
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'PGK')).to eql('PGK K30,175.93')
|
89
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'PHP')).to eql('PHP ₱30,175.93')
|
90
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'PYG')).to eql('PYG ₲3,017,593')
|
91
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'RUB')).to eql('RUB ₽30.175,93')
|
92
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'THB')).to eql('THB ฿30,175.93')
|
93
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TMT')).to eql('TMT T30,175.93')
|
94
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TOP')).to eql('TOP T$30,175.93')
|
95
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TRY')).to eql('TRY ₺30.175,93')
|
96
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'UAH')).to eql('UAH ₴30,175.93')
|
97
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'VND')).to eql('VND ₫3.017.593')
|
98
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'WST')).to eql('WST T30,175.93')
|
99
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ZAR')).to eql('ZAR R30,175.93')
|
100
|
+
end
|
101
|
+
|
102
|
+
it "respects currency's thousands separator and decimal mark" do
|
103
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
104
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR')).to eql('EUR €30.175,93')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "converts from currency's minor unit to major unit" do
|
108
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
109
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'JPY')).to eql('JPY ¥3,017,593')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'displays LTR for RTL symbols' do
|
113
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN')).to eql('AFN ؋30,175.93')
|
114
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'DZD')).to eql('DZD د.ج30,175.93')
|
115
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BHD')).to eql('BHD د.ب3,017.593')
|
116
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EGP')).to eql('EGP ج.م30,175.93')
|
117
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'IRR')).to eql('IRR ﷼30,175.93')
|
118
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'IQD')).to eql('IQD ع.د3,017.593')
|
119
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'JOD')).to eql('JOD د.ا3,017.593')
|
120
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'LYD')).to eql('LYD ل.د3,017.593')
|
121
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MAD')).to eql('MAD د.م.30,175.93')
|
122
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'QAR')).to eql('QAR ر.ق30,175.93')
|
123
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SYP')).to eql('SYP £S30,175.93')
|
124
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TND')).to eql('TND د.ت3,017.593')
|
125
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AED')).to eql('AED د.إ30,175.93')
|
126
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'YER')).to eql('YER ﷼30,175.93')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'defaults to USD' do
|
130
|
+
expect(MoneyHelper.money_to_text(30_175_93)).to eql('USD $30,175.93')
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'omits ISO code when with_currency is false' do
|
134
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false)).to eql('€30.175,93')
|
135
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_currency: false)).to eql('$30,175.93')
|
136
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_currency: false)).to eql('դր.30,175.93')
|
137
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false)).to eql('؋30,175.93')
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'omits symbol when with_symbol is false' do
|
141
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_symbol: false)).to eql('EUR 30.175,93')
|
142
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_symbol: false)).to eql('AUD 30,175.93')
|
143
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_symbol: false)).to eql('AMD 30,175.93')
|
144
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_symbol: false)).to eql('AFN 30,175.93')
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'omits ISO code and symbol when both with_currency and with_symbol are false' do
|
148
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false, with_symbol: false)).to eql('30.175,93')
|
149
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_currency: false, with_symbol: false)).to eql('30,175.93')
|
150
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_currency: false, with_symbol: false)).to eql('30,175.93')
|
151
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false, with_symbol: false)).to eql('30,175.93')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'returns an empty string if amount passed in is whitespace, empty string, or nil' do
|
155
|
+
expect(MoneyHelper.money_to_text(' ')).to eql('')
|
156
|
+
expect(MoneyHelper.money_to_text('')).to eql('')
|
157
|
+
expect(MoneyHelper.money_to_text(nil)).to eql('')
|
158
|
+
end
|
159
|
+
|
160
|
+
it "raises an exception when currency can't be found" do
|
161
|
+
expect do
|
162
|
+
MoneyHelper.money_to_text(30_175_93, currency: 'AAA')
|
163
|
+
end.to raise_error(Money::Currency::UnknownCurrency, "Unknown currency 'aaa'")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe 'symbol_with_optional_iso_code' do
|
168
|
+
it 'just includes the symbol for USD GBP EUR and MYR' do
|
169
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('EUR')).to eql('€')
|
170
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('GBP')).to eql('£')
|
171
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('MYR')).to eql('RM')
|
172
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('USD')).to eql('$')
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'includes the iso code as well for other currencies' do
|
176
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('AUD')).to eql('AUD $')
|
177
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('UZS')).to eql('UZS')
|
178
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('JPY')).to eql('JPY ¥')
|
147
179
|
end
|
148
180
|
end
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
MoneyHelper.money_range_to_text(
|
153
|
-
MoneyHelper.money_range_to_text(
|
154
|
-
MoneyHelper.money_range_to_text(
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
MoneyHelper.money_range_to_text(
|
160
|
-
MoneyHelper.money_range_to_text(
|
181
|
+
|
182
|
+
describe 'money_range_to_text' do
|
183
|
+
it 'includes no indicator for currency for the upper amount in range' do
|
184
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD')).to eql('USD $30,175.93 - 40,983.27')
|
185
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AUD')).to eql('AUD $30,175.93 - 40,983.27')
|
186
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AMD')).to eql('AMD դր.30,175.93 - 40,983.27')
|
187
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AFN')).to eql('AFN ؋30,175.93 - 40,983.27')
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'uses the special range amount delimeter when supplied' do
|
191
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD', delimiter: '-')).to eql('USD $30,175.93-40,983.27')
|
192
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AUD', delimiter: '-')).to eql('AUD $30,175.93-40,983.27')
|
193
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AMD', delimiter: '-')).to eql('AMD դր.30,175.93-40,983.27')
|
194
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AFN', delimiter: '-')).to eql('AFN ؋30,175.93-40,983.27')
|
161
195
|
end
|
196
|
+
|
162
197
|
it "prefixes the text 'Under ' when low amount not given" do
|
163
|
-
MoneyHelper.money_range_to_text(nil,
|
198
|
+
expect(MoneyHelper.money_range_to_text(nil, 40_983_27, currency: 'USD')).to eql('Under USD $40,983.27')
|
164
199
|
end
|
200
|
+
|
165
201
|
it "appends the text ' and up' when high amount not given" do
|
166
|
-
MoneyHelper.money_range_to_text(
|
202
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, nil, currency: 'USD')).to eql('USD $30,175.93 and up')
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'treats as a single price when low amount and high amount are identical' do
|
206
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'returns empty string when both amounts are nil' do
|
210
|
+
expect(MoneyHelper.money_range_to_text(nil, nil, currency: 'USD')).to eql('')
|
167
211
|
end
|
168
|
-
|
169
|
-
|
212
|
+
|
213
|
+
it "raises an exception when currency can't be found" do
|
214
|
+
expect do
|
215
|
+
MoneyHelper.money_range_to_text(10_000, 20_000, currency: 'ITL')
|
216
|
+
end.to raise_error(Money::Currency::UnknownCurrency, "Unknown currency 'itl'")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe 'symbol_with_optional_iso_code' do
|
221
|
+
it 'returns the symbol only if currency is in SYMBOL_ONLY list' do
|
222
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('EUR')).to eql('€')
|
223
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('USD')).to eql('$')
|
170
224
|
end
|
171
|
-
|
172
|
-
|
225
|
+
|
226
|
+
it 'returns iso code and symbol if symbol is in OK_SYMBOLS' do
|
227
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('INR')).to eql('INR ₹')
|
228
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('KHR')).to eql('KHR ៛')
|
229
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('KPW')).to eql('KPW ₩')
|
173
230
|
end
|
174
|
-
|
175
|
-
|
231
|
+
|
232
|
+
it 'returns only the iso code if symbol is not in OK_SYMBOLS' do
|
233
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('CHF')).to eql('CHF')
|
234
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('YER')).to eql('YER')
|
176
235
|
end
|
177
236
|
end
|
178
237
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,90 +1,129 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sahil Yakhmi
|
8
8
|
- Joey Aghion
|
9
|
-
|
9
|
+
- Matt Zikherman
|
10
|
+
- Sarah Weir
|
11
|
+
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
14
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
17
|
+
name: activesupport
|
16
18
|
requirement: !ruby/object:Gem::Requirement
|
17
19
|
requirements:
|
18
|
-
- -
|
20
|
+
- - ">="
|
19
21
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
22
|
+
version: '0'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
24
26
|
requirements:
|
25
|
-
- -
|
27
|
+
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
29
|
+
version: '0'
|
28
30
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
31
|
+
name: money
|
30
32
|
requirement: !ruby/object:Gem::Requirement
|
31
33
|
requirements:
|
32
|
-
- -
|
34
|
+
- - '='
|
33
35
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
36
|
+
version: 6.16.0
|
35
37
|
type: :runtime
|
36
38
|
prerelease: false
|
37
39
|
version_requirements: !ruby/object:Gem::Requirement
|
38
40
|
requirements:
|
39
|
-
- -
|
41
|
+
- - '='
|
40
42
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
43
|
+
version: 6.16.0
|
42
44
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
45
|
+
name: appraisal
|
44
46
|
requirement: !ruby/object:Gem::Requirement
|
45
47
|
requirements:
|
46
|
-
- -
|
48
|
+
- - ">="
|
47
49
|
- !ruby/object:Gem::Version
|
48
50
|
version: '0'
|
49
51
|
type: :development
|
50
52
|
prerelease: false
|
51
53
|
version_requirements: !ruby/object:Gem::Requirement
|
52
54
|
requirements:
|
53
|
-
- -
|
55
|
+
- - ">="
|
54
56
|
- !ruby/object:Gem::Version
|
55
57
|
version: '0'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - "~>"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '3'
|
56
72
|
description: A simple module to assist in formatting unambiguous prices and price
|
57
73
|
ranges in international currencies in a Roman Script context.
|
58
|
-
email:
|
74
|
+
email: matt@artsymail.com
|
59
75
|
executables: []
|
60
76
|
extensions: []
|
61
77
|
extra_rdoc_files: []
|
62
78
|
files:
|
79
|
+
- ".circleci/config.yml"
|
80
|
+
- ".gitignore"
|
81
|
+
- ".rubocop.yml"
|
82
|
+
- ".rubocop_todo.yml"
|
83
|
+
- Appraisals
|
84
|
+
- CHANGELOG.md
|
85
|
+
- Gemfile
|
86
|
+
- LICENSE.md
|
87
|
+
- README.md
|
88
|
+
- RELEASING.md
|
89
|
+
- Rakefile
|
90
|
+
- gemfiles/activesupport_40.gemfile
|
91
|
+
- gemfiles/activesupport_41.gemfile
|
92
|
+
- gemfiles/activesupport_42.gemfile
|
93
|
+
- gemfiles/activesupport_50.gemfile
|
94
|
+
- gemfiles/activesupport_51.gemfile
|
95
|
+
- gemfiles/activesupport_52.gemfile
|
96
|
+
- gemfiles/activesupport_edge.gemfile
|
63
97
|
- lib/money_helper.rb
|
98
|
+
- lib/version.rb
|
99
|
+
- money_helper.gemspec
|
64
100
|
- spec/money_helper_spec.rb
|
65
|
-
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/version_spec.rb
|
103
|
+
homepage: https://github.com/artsy/money_helper
|
66
104
|
licenses:
|
67
105
|
- MIT
|
68
106
|
metadata: {}
|
69
|
-
post_install_message:
|
107
|
+
post_install_message:
|
70
108
|
rdoc_options: []
|
71
109
|
require_paths:
|
72
110
|
- lib
|
73
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
112
|
requirements:
|
75
|
-
- -
|
113
|
+
- - ">="
|
76
114
|
- !ruby/object:Gem::Version
|
77
115
|
version: '0'
|
78
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
117
|
requirements:
|
80
|
-
- -
|
118
|
+
- - ">="
|
81
119
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
120
|
+
version: 1.3.6
|
83
121
|
requirements: []
|
84
|
-
|
85
|
-
|
86
|
-
signing_key:
|
122
|
+
rubygems_version: 3.1.4
|
123
|
+
signing_key:
|
87
124
|
specification_version: 4
|
88
|
-
summary: MoneyHelper international price formatting utility
|
125
|
+
summary: MoneyHelper international price formatting utility.
|
89
126
|
test_files:
|
90
127
|
- spec/money_helper_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/version_spec.rb
|