money_helper 1.0.0 → 3.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 +45 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +23 -0
- data/.rubocop_todo.yml +14 -0
- data/Appraisals +19 -0
- data/CHANGELOG.md +50 -0
- data/Gemfile +8 -0
- data/LICENSE.md +20 -0
- data/README.md +49 -0
- data/RELEASING.md +65 -0
- data/Rakefile +19 -0
- data/UPGRADING.md +44 -0
- data/gemfiles/activesupport_52.gemfile +10 -0
- data/gemfiles/activesupport_60.gemfile +10 -0
- data/gemfiles/activesupport_61.gemfile +10 -0
- data/gemfiles/activesupport_edge.gemfile +13 -0
- data/lib/money_helper.rb +59 -37
- data/lib/version.rb +5 -0
- data/money_helper.gemspec +24 -0
- data/spec/money_helper_spec.rb +229 -163
- data/spec/spec_helper.rb +8 -0
- data/spec/version_spec.rb +9 -0
- metadata +62 -25
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MGFjMWQ5MTRlMzVkYWRjMTA0ZGI1NDQxNjk3NzUzNDRjZWEzM2ZmOA==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8fc38d5c4921667c0f06286f5058378d60658b3f991dd7a343f5ab597384560c
|
4
|
+
data.tar.gz: c88db16a193d5674d9f902466aace23c8b7b1a0f71b89733589a05be7059049b
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YzgxYWRlN2YyMGYyODJkNDI4NmI4ZjliZmM4MTM0ZTMzYTc1MWRjOWFlOTE4
|
11
|
-
YmJiY2NiMmU4YzFhM2JlNjM0M2EyYzE2ZGI3MmIzY2YwOGQ3MDA=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZTVkOWYyZDMzOWM1NmY5NDc1MTRlYmFkNDIwNjk3N2VkNDUwNDI5YWZkZGVi
|
14
|
-
NTAzM2ZhYmQzZWJmNDA3YTllYTg5ZTg1MDcwYjQ0ZmY2MjJlMmI2MGEyMTFj
|
15
|
-
M2NlMjllZDczMDgxZWE2NDhiMzMwYTc0MGZmMzYxMzlhYTUzMDU=
|
6
|
+
metadata.gz: 1c258cca4d8ac444695faedd9245d1f805bcb5534bcf6f864dffdcfe330bf8f54f6c10caf800e32c1c2621bc523f6277acde3821a16c6a11edf31b777cdbdc6b
|
7
|
+
data.tar.gz: 8133b959081243c17b6d160ec72a802ed79648989c60ebaca8546a8509cc145b1148f89de4cc1e4ee89cc51459cc0e54fcf58f29a7d5fd412b4f1a93a85744fa
|
@@ -0,0 +1,45 @@
|
|
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.6", "2.7", "3.0"]
|
42
|
+
activesupport_version: ["52", "60", "61", "edge"]
|
43
|
+
exclude:
|
44
|
+
- ruby_version: "2.6"
|
45
|
+
activesupport_version: "edge"
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- vendor/**/*
|
6
|
+
- gemfiles/vendor/**/*
|
7
|
+
NewCops: enable
|
8
|
+
SuggestExtensions: false
|
9
|
+
|
10
|
+
Layout/LineLength:
|
11
|
+
Max: 512
|
12
|
+
|
13
|
+
Metrics:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Naming/MethodName:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/AsciiComments:
|
23
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2021-09-21 17:26:48 UTC using RuboCop version 1.21.0.
|
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: 1
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
|
+
Exclude:
|
14
|
+
- 'money_helper.gemspec'
|
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise 'activesupport_52' do
|
4
|
+
gem 'activesupport', '~> 5.2.6'
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise 'activesupport_60' do
|
8
|
+
gem 'activesupport', '~> 6.0.4'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise 'activesupport_61' do
|
12
|
+
gem 'activesupport', '~> 6.1.4'
|
13
|
+
end
|
14
|
+
|
15
|
+
appraise 'activesupport_edge' do
|
16
|
+
git 'git://github.com/rails/rails.git' do
|
17
|
+
gem 'activesupport', require: 'active_support'
|
18
|
+
end
|
19
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
### 3.0.0 (Next)
|
2
|
+
|
3
|
+
* [#27](https://github.com/artsy/money_helper/pull/27): Update `money_to_text` to pass `format` options to `Money#format` for additional features such as `no_cents` - [@agrberg](https://github.com/agrberg).
|
4
|
+
* Your contribution here.
|
5
|
+
|
6
|
+
### 2.0.0 (2021-09-20)
|
7
|
+
|
8
|
+
#### Breaking Changes
|
9
|
+
|
10
|
+
* [#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)
|
11
|
+
|
12
|
+
### 1.0.2 (2019-04-19)
|
13
|
+
|
14
|
+
* [#16](https://github.com/artsy/money_helper/pull/16): Remove deprecation warnings - [@sweir27](https://github.com/sweir27).
|
15
|
+
* [#15](https://github.com/artsy/money_helper/pull/15): Added Rubocop - [@dblock](https://github.com/dblock).
|
16
|
+
|
17
|
+
### 1.0.1 (2017-04-03)
|
18
|
+
|
19
|
+
* Relaxed activesupport version dependency - [@dblock](https://github.com/dblock).
|
20
|
+
* The `money_to_text` method now takes options - [@mzikherman](https://github.com/mzikherman).
|
21
|
+
* Added `symbol_with_optional_iso_code` - [@mzikherman](https://github.com/mzikherman).
|
22
|
+
|
23
|
+
### 1.0.0 (2015-03-07)
|
24
|
+
|
25
|
+
* Added compatibility with Money 6.5.1+, including new currency symbols - [@syakhmi](https://github.com/syakhmi).
|
26
|
+
|
27
|
+
### 0.0.5 (2014-04-12)
|
28
|
+
|
29
|
+
* Added compatibility with Money 6.1+ - [@syakhmi](https://github.com/syakhmi).
|
30
|
+
* Dropped support for pre 6.0 versions of Money - [@syakhmi](https://github.com/syakhmi).
|
31
|
+
|
32
|
+
### 0.0.4 (2014-01-08)
|
33
|
+
|
34
|
+
* Added compatibility with Money 6.x - [@dblock](https://github.com/dblock).
|
35
|
+
* Avoid failing on deprecated currencies (such as ITL) - [@joeyAghion](https://github.com/joeyAghion).
|
36
|
+
|
37
|
+
### 0.0.3 (2013-07-17)
|
38
|
+
|
39
|
+
* Added support for currencies that don't have a symbol, eg. Uzbekistan Som (UZS) - [@dblock](https://github.com/dblock).
|
40
|
+
|
41
|
+
### 0.0.2 (2013-07-16)
|
42
|
+
|
43
|
+
* Added unit tests - [@syakhmi](https://github.com/syakhmi).
|
44
|
+
* Added support for Cambodian riel - [@syakhmi](https://github.com/syakhmi).
|
45
|
+
* Added dependencies to gemspec - [@syakhmi](https://github.com/syakhmi).
|
46
|
+
* Now defaults to USD when currency not specified - [@syakhmi](https://github.com/syakhmi).
|
47
|
+
|
48
|
+
### 0.0.1 (2013-07-12)
|
49
|
+
|
50
|
+
* 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/main.svg?style=svg
|
43
|
+
[circleci]: https://circleci.com/gh/artsy/money_helper/tree/main
|
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,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
|
7
|
+
Bundler.setup :default, :development
|
8
|
+
|
9
|
+
require 'rspec/core'
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
13
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'rubocop/rake_task'
|
17
|
+
RuboCop::RakeTask.new
|
18
|
+
|
19
|
+
task default: %i[rubocop spec]
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Upgrading MoneyHelper
|
2
|
+
=====================
|
3
|
+
|
4
|
+
### Upgrading to >= 3.0.0
|
5
|
+
|
6
|
+
#### `money_to_text` format options
|
7
|
+
|
8
|
+
Prior to 3.0.0 `money_to_text` took a named argument `with_symbol`. The default value was `true` and assing `false` would omit the currency symbol.
|
9
|
+
|
10
|
+
This data was later passed to the `Money#format` method with a default `format` string of `'%u%n'`. Users of `MoneyHelper` could not modify the format string or utilize additional format options, such as `no_cents: false`.
|
11
|
+
|
12
|
+
In 3.0.0 this was changed so `money_to_text` can take an optional `format` argument which is eventually passed to `Money#format` with only the slight modification of adding in `format: '%u%n'` if this key is not present.
|
13
|
+
|
14
|
+
### Upgrading to >= 2.0.0
|
15
|
+
|
16
|
+
#### `money_to_text` amount is now given in minor units
|
17
|
+
|
18
|
+
Prior to 2.0.0 `money_to_text` took an amount in a currency's major units and converted this value internally before passing to `Money#new` which expects values in their minor unit (i.e. For USD the major unit is Dollars and the minor unit is Cents). This version removes the autoscaling so `money_to_text` can take amounts in their minor units.
|
19
|
+
|
20
|
+
Additionally, `currency`, `number_only`, and `options` were removed as postional arguments and replaced with named arguments `currency`, `with_currency`, and `with_symbol` with `'USD'`, `true` and `true` as their default arguments respectively.
|
21
|
+
|
22
|
+
One minor difference is that `currency` can be omited completely where as in < 2.0.0 `''` or `nil` was required to be passed for the default of `'USD'` to be used.
|
23
|
+
|
24
|
+
Finally the automatic omission of certain currency codes (USD, GBP, EUR, and MYR) is no longer supported. To replicate this behavior you must explicitly specify `with_currency: false`.
|
25
|
+
|
26
|
+
The following illustrates the primary difference in usage.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# Before 2.0.0
|
30
|
+
|
31
|
+
MoneyHelper.money_to_text(123, 'USD')
|
32
|
+
# => $123
|
33
|
+
|
34
|
+
# After 2.0.0
|
35
|
+
|
36
|
+
MoneyHelper.money_to_text(123) # `currency: 'USD'` is the default
|
37
|
+
# => USD $1.23
|
38
|
+
|
39
|
+
# to replicate previous behavior almost exactly
|
40
|
+
MoneyHelper.money_to_text(12300, with_currency: false)
|
41
|
+
# => $123.00
|
42
|
+
|
43
|
+
# Note the inclusion of the cents. The ability to remove this was added in 3.0.0 as another breaking change
|
44
|
+
```
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file was generated by Appraisal
|
4
|
+
|
5
|
+
source 'http://rubygems.org'
|
6
|
+
|
7
|
+
git 'git://github.com/rails/rails.git' do
|
8
|
+
gem 'activesupport', require: 'active_support'
|
9
|
+
end
|
10
|
+
|
11
|
+
gem 'rubocop', '1.21.0'
|
12
|
+
|
13
|
+
gemspec path: '../'
|
data/lib/money_helper.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'version'
|
2
4
|
|
3
5
|
require 'active_support/core_ext/object/blank'
|
4
6
|
require 'money'
|
5
7
|
|
6
8
|
module MoneyHelper
|
9
|
+
Money.locale_backend = :currency
|
7
10
|
I18n.enforce_available_locales = false
|
8
11
|
|
9
|
-
SYMBOL_ONLY = %w
|
10
|
-
OK_SYMBOLS = %w
|
12
|
+
SYMBOL_ONLY = %w[USD GBP EUR MYR].freeze # don't use ISO code
|
13
|
+
OK_SYMBOLS = %w[
|
11
14
|
$ £ € ¥ 元 р. L ƒ ৳ P R$ K ₡ D ლ ₵ Q G ₹ Rp ₪ ₩ ₭ R RM ₨ ₮ դր. C$ ₦ ₲ ₱ T ฿ T$ m ₴ ₫ ៛ ₺ E ₽
|
12
|
-
|
15
|
+
].freeze # ok to include in string
|
13
16
|
|
14
17
|
##
|
15
18
|
# Formats a single amount in the given currency into a price string. Defaults to USD if currency not
|
@@ -17,27 +20,38 @@ module MoneyHelper
|
|
17
20
|
#
|
18
21
|
# = Example
|
19
22
|
#
|
20
|
-
#
|
23
|
+
# MoneyHelper.money_to_text(30_175_93, currency: 'USD') #=> 'USD $30,175.93'
|
24
|
+
# MoneyHelper.money_to_text(30_175_93, currency: 'EUR') #=> 'EUR €30.175,93'
|
25
|
+
# MoneyHelper.money_to_text(30_175_93) #=> 'USD $30,175.93'
|
21
26
|
#
|
22
27
|
# = Arguments
|
23
28
|
#
|
24
|
-
#
|
25
|
-
# currency: (String)
|
26
|
-
#
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# amount_minor: (Integer) amount in minor unit
|
30
|
+
# currency: (String) optional ISO currency code, defaulting to USD
|
31
|
+
# with_currency: (Boolean) optional flag to include ISO currency code, defaulting to true
|
32
|
+
# format: (Hash) optional formatting options to pass to `Money#format` e.g.:
|
33
|
+
# no_cents: (Boolean) optional flag to exclude cents, defaulting to false
|
34
|
+
# symbol: (Boolean) optional flag to include currency symbol, defaulting to true
|
35
|
+
def self.money_to_text(amount_minor, currency: 'USD', with_currency: true, format: {})
|
36
|
+
return '' if amount_minor.blank?
|
37
|
+
|
38
|
+
format_options = { format: '%u%n' }.merge(format)
|
39
|
+
|
40
|
+
formatted_amount = Money.new(amount_minor, currency).format(format_options)
|
41
|
+
formatted_currency = with_currency ? currency.upcase : ''
|
42
|
+
|
43
|
+
"#{formatted_currency} #{formatted_amount}".strip
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.symbol_with_optional_iso_code(currency = 'USD')
|
32
47
|
symbol = symbol_for_code(currency)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
}).delete(' ')
|
48
|
+
if SYMBOL_ONLY.include?(currency)
|
49
|
+
symbol
|
50
|
+
elsif symbol && OK_SYMBOLS.include?(symbol)
|
51
|
+
"#{iso_for_currency(currency)} #{symbol}"
|
52
|
+
else
|
53
|
+
iso_for_currency(currency).to_s
|
54
|
+
end
|
41
55
|
end
|
42
56
|
|
43
57
|
##
|
@@ -45,42 +59,50 @@ module MoneyHelper
|
|
45
59
|
#
|
46
60
|
# = Example
|
47
61
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
62
|
+
# MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD') #=> 'USD $30,175.93 - 40,983.27'
|
63
|
+
# MoneyHelper.money_range_to_text(30_175_93, 40_983_27) #=> 'USD $30,175.93 - 40,983.27'
|
64
|
+
# MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'EUR') #=> 'EUR €30.175,93 - 40.983,27'
|
65
|
+
# MoneyHelper.money_range_to_text(30_175_93, 40_983_27, delimiter: ' ... ') #=> 'USD $30,175.93 ... 40,983.27'
|
52
66
|
#
|
53
67
|
# = Arguments
|
54
68
|
#
|
55
|
-
# low: (
|
56
|
-
# high: (
|
57
|
-
# currency: (String)
|
69
|
+
# low: (Integer) amount in minor unit
|
70
|
+
# high: (Integer) amount in minor unit
|
71
|
+
# currency: (String) optional ISO currency code, defaulting to USD
|
58
72
|
# delimiter: (String) optional
|
59
|
-
def self.money_range_to_text(low, high, currency, delimiter
|
73
|
+
def self.money_range_to_text(low, high, currency: 'USD', delimiter: ' - ')
|
60
74
|
if low.blank? && high.blank?
|
61
|
-
|
75
|
+
''
|
62
76
|
elsif low.blank?
|
63
|
-
"Under
|
77
|
+
"Under #{money_to_text(high, currency: currency)}"
|
64
78
|
elsif high.blank?
|
65
|
-
money_to_text(low, currency)
|
79
|
+
"#{money_to_text(low, currency: currency)} and up"
|
66
80
|
elsif low == high
|
67
|
-
money_to_text(low, currency)
|
81
|
+
money_to_text(low, currency: currency)
|
68
82
|
else
|
69
|
-
|
83
|
+
formatted_low = money_to_text(low, currency: currency)
|
84
|
+
formatted_high = money_to_text(high, currency: currency, with_currency: false, format: { symbol: false })
|
85
|
+
[formatted_low, formatted_high].compact.join(delimiter)
|
70
86
|
end
|
71
87
|
end
|
72
88
|
|
73
|
-
private
|
74
|
-
|
75
89
|
def self.code_valid?(code)
|
76
90
|
Money::Currency.stringified_keys.include?(code.downcase)
|
77
91
|
end
|
78
92
|
|
93
|
+
def self.iso_for_currency(code)
|
94
|
+
return unless code && code_valid?(code)
|
95
|
+
|
96
|
+
Money::Currency.new(code).iso_code.tap do |iso_code|
|
97
|
+
iso_code.strip! if iso_code.present?
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
79
101
|
def self.symbol_for_code(code)
|
80
102
|
return unless code && code_valid?(code)
|
103
|
+
|
81
104
|
Money::Currency.new(code).symbol.tap do |symbol|
|
82
105
|
symbol.strip! if symbol.present?
|
83
106
|
end
|
84
107
|
end
|
85
|
-
|
86
108
|
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
require 'version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'money_helper'
|
8
|
+
s.version = MoneyHelper::VERSION
|
9
|
+
s.summary = 'MoneyHelper international price formatting utility.'
|
10
|
+
s.description = 'A simple module to assist in formatting unambiguous prices and price ranges in international currencies in a Roman Script context.'
|
11
|
+
s.authors = ['Sahil Yakhmi', 'Joey Aghion', 'Matt Zikherman', 'Sarah Weir']
|
12
|
+
s.email = 'matt@artsymail.com'
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.required_rubygems_version = '>= 1.3.6'
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
s.homepage = 'https://github.com/artsy/money_helper'
|
19
|
+
s.add_dependency('activesupport')
|
20
|
+
s.add_dependency('money', '6.16.0')
|
21
|
+
s.add_development_dependency('appraisal')
|
22
|
+
s.add_development_dependency('rspec', '~> 3')
|
23
|
+
s.licenses = ['MIT']
|
24
|
+
end
|
data/spec/money_helper_spec.rb
CHANGED
@@ -1,178 +1,244 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
5
|
describe MoneyHelper do
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
expect(MoneyHelper.money_to_text(
|
9
|
-
expect(MoneyHelper.money_to_text(
|
10
|
-
expect(MoneyHelper.money_to_text(
|
11
|
-
expect(MoneyHelper.money_to_text(
|
12
|
-
expect(MoneyHelper.money_to_text(
|
13
|
-
|
14
|
-
|
15
|
-
expect(MoneyHelper.money_to_text(
|
16
|
-
expect(MoneyHelper.money_to_text(
|
17
|
-
expect(MoneyHelper.money_to_text(
|
18
|
-
expect(MoneyHelper.money_to_text(
|
19
|
-
expect(MoneyHelper.money_to_text(
|
20
|
-
expect(MoneyHelper.money_to_text(
|
21
|
-
expect(MoneyHelper.money_to_text(
|
22
|
-
expect(MoneyHelper.money_to_text(
|
23
|
-
expect(MoneyHelper.money_to_text(
|
24
|
-
expect(MoneyHelper.money_to_text(
|
25
|
-
expect(MoneyHelper.money_to_text(
|
26
|
-
expect(MoneyHelper.money_to_text(
|
27
|
-
expect(MoneyHelper.money_to_text(
|
28
|
-
expect(MoneyHelper.money_to_text(
|
29
|
-
expect(MoneyHelper.money_to_text(
|
30
|
-
expect(MoneyHelper.money_to_text(
|
31
|
-
expect(MoneyHelper.money_to_text(
|
32
|
-
expect(MoneyHelper.money_to_text(
|
33
|
-
expect(MoneyHelper.money_to_text(
|
34
|
-
expect(MoneyHelper.money_to_text(
|
35
|
-
expect(MoneyHelper.money_to_text(
|
36
|
-
expect(MoneyHelper.money_to_text(
|
37
|
-
expect(MoneyHelper.money_to_text(
|
38
|
-
expect(MoneyHelper.money_to_text(
|
39
|
-
|
40
|
-
expect(MoneyHelper.money_to_text(
|
41
|
-
|
42
|
-
expect(MoneyHelper.money_to_text(
|
43
|
-
expect(MoneyHelper.money_to_text(
|
44
|
-
expect(MoneyHelper.money_to_text(
|
45
|
-
|
46
|
-
expect(MoneyHelper.money_to_text(
|
47
|
-
|
48
|
-
expect(MoneyHelper.money_to_text(
|
49
|
-
expect(MoneyHelper.money_to_text(
|
50
|
-
|
51
|
-
expect(MoneyHelper.money_to_text(
|
52
|
-
expect(MoneyHelper.money_to_text(
|
53
|
-
|
54
|
-
expect(MoneyHelper.money_to_text(
|
55
|
-
expect(MoneyHelper.money_to_text(
|
56
|
-
expect(MoneyHelper.money_to_text(
|
57
|
-
expect(MoneyHelper.money_to_text(
|
58
|
-
|
59
|
-
expect(MoneyHelper.money_to_text(
|
60
|
-
|
61
|
-
|
62
|
-
expect(MoneyHelper.money_to_text(
|
63
|
-
|
64
|
-
|
65
|
-
expect(MoneyHelper.money_to_text(
|
66
|
-
|
67
|
-
|
68
|
-
expect(MoneyHelper.money_to_text(
|
69
|
-
|
70
|
-
expect(MoneyHelper.money_to_text(
|
71
|
-
expect(MoneyHelper.money_to_text(
|
72
|
-
|
73
|
-
expect(MoneyHelper.money_to_text(
|
74
|
-
|
75
|
-
|
76
|
-
expect(MoneyHelper.money_to_text(
|
77
|
-
expect(MoneyHelper.money_to_text(
|
78
|
-
expect(MoneyHelper.money_to_text(
|
79
|
-
expect(MoneyHelper.money_to_text(
|
80
|
-
expect(MoneyHelper.money_to_text(
|
81
|
-
expect(MoneyHelper.money_to_text(
|
82
|
-
expect(MoneyHelper.money_to_text(
|
83
|
-
expect(MoneyHelper.money_to_text(
|
84
|
-
expect(MoneyHelper.money_to_text(
|
85
|
-
expect(MoneyHelper.money_to_text(
|
86
|
-
expect(MoneyHelper.money_to_text(
|
87
|
-
expect(MoneyHelper.money_to_text(
|
88
|
-
expect(MoneyHelper.money_to_text(
|
89
|
-
expect(MoneyHelper.money_to_text(
|
90
|
-
expect(MoneyHelper.money_to_text(
|
91
|
-
expect(MoneyHelper.money_to_text(
|
92
|
-
expect(MoneyHelper.money_to_text(
|
93
|
-
expect(MoneyHelper.money_to_text(
|
94
|
-
expect(MoneyHelper.money_to_text(
|
95
|
-
expect(MoneyHelper.money_to_text(
|
96
|
-
expect(MoneyHelper.money_to_text(
|
97
|
-
expect(MoneyHelper.money_to_text(
|
98
|
-
expect(MoneyHelper.money_to_text(
|
99
|
-
expect(MoneyHelper.money_to_text(
|
100
|
-
expect(MoneyHelper.money_to_text(
|
101
|
-
expect(MoneyHelper.money_to_text(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
expect(MoneyHelper.money_to_text(
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
expect(MoneyHelper.money_to_text(
|
111
|
-
expect(MoneyHelper.money_to_text(
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
expect(MoneyHelper.money_to_text(
|
116
|
-
expect(MoneyHelper.money_to_text(
|
117
|
-
expect(MoneyHelper.money_to_text(
|
118
|
-
expect(MoneyHelper.money_to_text(
|
119
|
-
expect(MoneyHelper.money_to_text(
|
120
|
-
expect(MoneyHelper.money_to_text(
|
121
|
-
expect(MoneyHelper.money_to_text(
|
122
|
-
expect(MoneyHelper.money_to_text(
|
123
|
-
expect(MoneyHelper.money_to_text(
|
124
|
-
expect(MoneyHelper.money_to_text(
|
125
|
-
expect(MoneyHelper.money_to_text(
|
126
|
-
expect(MoneyHelper.money_to_text(
|
127
|
-
expect(MoneyHelper.money_to_text(
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
expect(MoneyHelper.money_to_text(
|
137
|
-
expect(MoneyHelper.money_to_text(
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
expect(MoneyHelper.money_to_text(
|
146
|
-
expect(MoneyHelper.money_to_text(
|
6
|
+
describe 'money_to_text' do
|
7
|
+
it 'includes ISO code and symbol' do
|
8
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD')).to eql('AUD $30,175.93')
|
9
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ARS')).to eql('ARS $30.175,93')
|
10
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BBD')).to eql('BBD $30,175.93')
|
11
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BMD')).to eql('BMD $30,175.93')
|
12
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BND')).to eql('BND $30,175.93')
|
13
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BSD')).to eql('BSD $30,175.93')
|
14
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BZD')).to eql('BZD $30,175.93')
|
15
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CAD')).to eql('CAD $30,175.93')
|
16
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CLP')).to eql('CLP $3.017.593')
|
17
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'COP')).to eql('COP $30.175,93')
|
18
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CUC')).to eql('CUC $30,175.93')
|
19
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CUP')).to eql('CUP $30,175.93')
|
20
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'DOP')).to eql('DOP $30,175.93')
|
21
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'FJD')).to eql('FJD $30,175.93')
|
22
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GYD')).to eql('GYD $30,175.93')
|
23
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'HKD')).to eql('HKD $30,175.93')
|
24
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'JMD')).to eql('JMD $30,175.93')
|
25
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'KYD')).to eql('KYD $30,175.93')
|
26
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'LRD')).to eql('LRD $30,175.93')
|
27
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MXN')).to eql('MXN $30,175.93')
|
28
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NAD')).to eql('NAD $30,175.93')
|
29
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NZD')).to eql('NZD $30,175.93')
|
30
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SBD')).to eql('SBD $30,175.93')
|
31
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SGD')).to eql('SGD $30,175.93')
|
32
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SRD')).to eql('SRD $30,175.93')
|
33
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TWD')).to eql('TWD $30,175.93')
|
34
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TTD')).to eql('TTD $30,175.93')
|
35
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'UYU')).to eql('UYU $U30.175,93')
|
36
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
37
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'XCD')).to eql('XCD $30,175.93')
|
38
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ZWL')).to eql('ZWL $30,175.93')
|
39
|
+
|
40
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR')).to eql('EUR €30.175,93')
|
41
|
+
|
42
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'FKP')).to eql('FKP £30,175.93')
|
43
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GBP')).to eql('GBP £30,175.93')
|
44
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GIP')).to eql('GIP £30,175.93')
|
45
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SDG')).to eql('SDG £30,175.93')
|
46
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SHP')).to eql('SHP £30,175.93')
|
47
|
+
|
48
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CNY')).to eql('CNY ¥30,175.93')
|
49
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'JPY')).to eql('JPY ¥3,017,593')
|
50
|
+
|
51
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ALL')).to eql('ALL L30,175.93')
|
52
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'HNL')).to eql('HNL L30,175.93')
|
53
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'LSL')).to eql('LSL L30,175.93')
|
54
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MDL')).to eql('MDL L30,175.93')
|
55
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MYR')).to eql('MYR RM30,175.93')
|
56
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'RON')).to eql('RON Lei30.175,93')
|
57
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SZL')).to eql('SZL E30,175.93')
|
58
|
+
|
59
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ANG')).to eql('ANG ƒ30.175,93')
|
60
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AWG')).to eql('AWG ƒ30,175.93')
|
61
|
+
|
62
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BWP')).to eql('BWP P30,175.93')
|
63
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MOP')).to eql('MOP P30,175.93')
|
64
|
+
|
65
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'CRC')).to eql('CRC ₡30.175,93')
|
66
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SVC')).to eql('SVC ₡30,175.93')
|
67
|
+
|
68
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MUR')).to eql('MUR ₨30,175.93')
|
69
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NPR')).to eql('NPR Rs.30,175.93')
|
70
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'PKR')).to eql('PKR ₨30,175.93')
|
71
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SCR')).to eql('SCR ₨30,175.93')
|
72
|
+
|
73
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD')).to eql('AMD դր.30,175.93')
|
74
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BDT')).to eql('BDT ৳30,175.93')
|
75
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BRL')).to eql('BRL R$30.175,93')
|
76
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GEL')).to eql('GEL ლ30,175.93')
|
77
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GHS')).to eql('GHS ₵30,175.93')
|
78
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GMD')).to eql('GMD D30,175.93')
|
79
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'GTQ')).to eql('GTQ Q30,175.93')
|
80
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'HTG')).to eql('HTG G30,175.93')
|
81
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'IDR')).to eql('IDR Rp30.175,93')
|
82
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ILS')).to eql('ILS ₪30,175.93')
|
83
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'INR')).to eql('INR ₹30,175.93')
|
84
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'KHR')).to eql('KHR ៛30,175.93')
|
85
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'KPW')).to eql('KPW ₩30,175.93')
|
86
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'LAK')).to eql('LAK ₭30,175.93')
|
87
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MNT')).to eql('MNT ₮30,175.93')
|
88
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NGN')).to eql('NGN ₦30,175.93')
|
89
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'NIO')).to eql('NIO C$30,175.93')
|
90
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'PGK')).to eql('PGK K30,175.93')
|
91
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'PHP')).to eql('PHP ₱30,175.93')
|
92
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'PYG')).to eql('PYG ₲3,017,593')
|
93
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'RUB')).to eql('RUB ₽30.175,93')
|
94
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'THB')).to eql('THB ฿30,175.93')
|
95
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TMT')).to eql('TMT T30,175.93')
|
96
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TOP')).to eql('TOP T$30,175.93')
|
97
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TRY')).to eql('TRY ₺30.175,93')
|
98
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'UAH')).to eql('UAH ₴30,175.93')
|
99
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'VND')).to eql('VND ₫3.017.593')
|
100
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'WST')).to eql('WST T30,175.93')
|
101
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'ZAR')).to eql('ZAR R30,175.93')
|
102
|
+
end
|
103
|
+
|
104
|
+
it "respects currency's thousands separator and decimal mark" do
|
105
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
106
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR')).to eql('EUR €30.175,93')
|
107
|
+
end
|
108
|
+
|
109
|
+
it "converts from currency's minor unit to major unit" do
|
110
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
111
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'JPY')).to eql('JPY ¥3,017,593')
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'displays LTR for RTL symbols' do
|
115
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN')).to eql('AFN ؋30,175.93')
|
116
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'DZD')).to eql('DZD د.ج30,175.93')
|
117
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'BHD')).to eql('BHD د.ب3,017.593')
|
118
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EGP')).to eql('EGP ج.م30,175.93')
|
119
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'IRR')).to eql('IRR ﷼30,175.93')
|
120
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'IQD')).to eql('IQD ع.د3,017.593')
|
121
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'JOD')).to eql('JOD د.ا3,017.593')
|
122
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'LYD')).to eql('LYD ل.د3,017.593')
|
123
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'MAD')).to eql('MAD د.م.30,175.93')
|
124
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'QAR')).to eql('QAR ر.ق30,175.93')
|
125
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'SYP')).to eql('SYP £S30,175.93')
|
126
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'TND')).to eql('TND د.ت3,017.593')
|
127
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AED')).to eql('AED د.إ30,175.93')
|
128
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'YER')).to eql('YER ﷼30,175.93')
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'defaults to USD' do
|
132
|
+
expect(MoneyHelper.money_to_text(30_175_93)).to eql('USD $30,175.93')
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'omits ISO code when with_currency is false' do
|
136
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false)).to eql('€30.175,93')
|
137
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_currency: false)).to eql('$30,175.93')
|
138
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_currency: false)).to eql('դր.30,175.93')
|
139
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false)).to eql('؋30,175.93')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'omits symbol when `format: symbol:` is false' do
|
143
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', format: { symbol: false })).to eql('EUR 30.175,93')
|
144
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', format: { symbol: false })).to eql('AUD 30,175.93')
|
145
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', format: { symbol: false })).to eql('AMD 30,175.93')
|
146
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', format: { symbol: false })).to eql('AFN 30,175.93')
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'omits ISO code and symbol when both `with_currency` and `format: symbol:` are false' do
|
150
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false, format: { symbol: false })).to eql('30.175,93')
|
151
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_currency: false, format: { symbol: false })).to eql('30,175.93')
|
152
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_currency: false, format: { symbol: false })).to eql('30,175.93')
|
153
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false, format: { symbol: false })).to eql('30,175.93')
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'omits cents when `format: no_cents:` is true' do
|
157
|
+
expect(MoneyHelper.money_to_text(30_175_93, with_currency: false, format: { no_cents: true, symbol: false })).to eql('30,175')
|
158
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false, format: { no_cents: true, symbol: false })).to eql('30.175')
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'returns an empty string if amount passed in is whitespace, empty string, or nil' do
|
162
|
+
expect(MoneyHelper.money_to_text(' ')).to eql('')
|
163
|
+
expect(MoneyHelper.money_to_text('')).to eql('')
|
164
|
+
expect(MoneyHelper.money_to_text(nil)).to eql('')
|
165
|
+
end
|
166
|
+
|
167
|
+
it "raises an exception when currency can't be found" do
|
168
|
+
expect do
|
169
|
+
MoneyHelper.money_to_text(30_175_93, currency: 'AAA')
|
170
|
+
end.to raise_error(Money::Currency::UnknownCurrency, "Unknown currency 'aaa'")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe 'symbol_with_optional_iso_code' do
|
175
|
+
it 'just includes the symbol for USD GBP EUR and MYR' do
|
176
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('EUR')).to eql('€')
|
177
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('GBP')).to eql('£')
|
178
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('MYR')).to eql('RM')
|
179
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('USD')).to eql('$')
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'includes the iso code as well for other currencies' do
|
183
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('AUD')).to eql('AUD $')
|
184
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('UZS')).to eql('UZS')
|
185
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('JPY')).to eql('JPY ¥')
|
147
186
|
end
|
148
187
|
end
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
expect(MoneyHelper.money_range_to_text(
|
153
|
-
expect(MoneyHelper.money_range_to_text(
|
154
|
-
expect(MoneyHelper.money_range_to_text(
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
expect(MoneyHelper.money_range_to_text(
|
160
|
-
expect(MoneyHelper.money_range_to_text(
|
188
|
+
|
189
|
+
describe 'money_range_to_text' do
|
190
|
+
it 'includes no indicator for currency for the upper amount in range' do
|
191
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD')).to eql('USD $30,175.93 - 40,983.27')
|
192
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AUD')).to eql('AUD $30,175.93 - 40,983.27')
|
193
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AMD')).to eql('AMD դր.30,175.93 - 40,983.27')
|
194
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AFN')).to eql('AFN ؋30,175.93 - 40,983.27')
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'uses the special range amount delimeter when supplied' do
|
198
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'USD', delimiter: '-')).to eql('USD $30,175.93-40,983.27')
|
199
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AUD', delimiter: '-')).to eql('AUD $30,175.93-40,983.27')
|
200
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AMD', delimiter: '-')).to eql('AMD դր.30,175.93-40,983.27')
|
201
|
+
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
202
|
end
|
203
|
+
|
162
204
|
it "prefixes the text 'Under ' when low amount not given" do
|
163
|
-
expect(MoneyHelper.money_range_to_text(nil,
|
205
|
+
expect(MoneyHelper.money_range_to_text(nil, 40_983_27, currency: 'USD')).to eql('Under USD $40,983.27')
|
164
206
|
end
|
207
|
+
|
165
208
|
it "appends the text ' and up' when high amount not given" do
|
166
|
-
expect(MoneyHelper.money_range_to_text(
|
209
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, nil, currency: 'USD')).to eql('USD $30,175.93 and up')
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'treats as a single price when low amount and high amount are identical' do
|
213
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'returns empty string when both amounts are nil' do
|
217
|
+
expect(MoneyHelper.money_range_to_text(nil, nil, currency: 'USD')).to eql('')
|
167
218
|
end
|
168
|
-
|
169
|
-
|
219
|
+
|
220
|
+
it "raises an exception when currency can't be found" do
|
221
|
+
expect do
|
222
|
+
MoneyHelper.money_range_to_text(10_000, 20_000, currency: 'ITL')
|
223
|
+
end.to raise_error(Money::Currency::UnknownCurrency, "Unknown currency 'itl'")
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe 'symbol_with_optional_iso_code' do
|
228
|
+
it 'returns the symbol only if currency is in SYMBOL_ONLY list' do
|
229
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('EUR')).to eql('€')
|
230
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('USD')).to eql('$')
|
170
231
|
end
|
171
|
-
|
172
|
-
|
232
|
+
|
233
|
+
it 'returns iso code and symbol if symbol is in OK_SYMBOLS' do
|
234
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('INR')).to eql('INR ₹')
|
235
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('KHR')).to eql('KHR ៛')
|
236
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('KPW')).to eql('KPW ₩')
|
173
237
|
end
|
174
|
-
|
175
|
-
|
238
|
+
|
239
|
+
it 'returns only the iso code if symbol is not in OK_SYMBOLS' do
|
240
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('CHF')).to eql('CHF')
|
241
|
+
expect(MoneyHelper.symbol_with_optional_iso_code('YER')).to eql('YER')
|
176
242
|
end
|
177
243
|
end
|
178
244
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,90 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.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: 2022-02-16 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
|
+
- - '='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 6.16.0
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: appraisal
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
40
56
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
57
|
+
version: '0'
|
42
58
|
- !ruby/object:Gem::Dependency
|
43
59
|
name: rspec
|
44
60
|
requirement: !ruby/object:Gem::Requirement
|
45
61
|
requirements:
|
46
|
-
- - ~>
|
62
|
+
- - "~>"
|
47
63
|
- !ruby/object:Gem::Version
|
48
64
|
version: '3'
|
49
65
|
type: :development
|
50
66
|
prerelease: false
|
51
67
|
version_requirements: !ruby/object:Gem::Requirement
|
52
68
|
requirements:
|
53
|
-
- - ~>
|
69
|
+
- - "~>"
|
54
70
|
- !ruby/object:Gem::Version
|
55
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
|
+
- UPGRADING.md
|
91
|
+
- gemfiles/activesupport_52.gemfile
|
92
|
+
- gemfiles/activesupport_60.gemfile
|
93
|
+
- gemfiles/activesupport_61.gemfile
|
94
|
+
- gemfiles/activesupport_edge.gemfile
|
63
95
|
- lib/money_helper.rb
|
96
|
+
- lib/version.rb
|
97
|
+
- money_helper.gemspec
|
64
98
|
- spec/money_helper_spec.rb
|
65
|
-
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
- spec/version_spec.rb
|
101
|
+
homepage: https://github.com/artsy/money_helper
|
66
102
|
licenses:
|
67
103
|
- MIT
|
68
104
|
metadata: {}
|
69
|
-
post_install_message:
|
105
|
+
post_install_message:
|
70
106
|
rdoc_options: []
|
71
107
|
require_paths:
|
72
108
|
- lib
|
73
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
110
|
requirements:
|
75
|
-
- -
|
111
|
+
- - ">="
|
76
112
|
- !ruby/object:Gem::Version
|
77
113
|
version: '0'
|
78
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
115
|
requirements:
|
80
|
-
- -
|
116
|
+
- - ">="
|
81
117
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
118
|
+
version: 1.3.6
|
83
119
|
requirements: []
|
84
|
-
|
85
|
-
|
86
|
-
signing_key:
|
120
|
+
rubygems_version: 3.2.27
|
121
|
+
signing_key:
|
87
122
|
specification_version: 4
|
88
|
-
summary: MoneyHelper international price formatting utility
|
123
|
+
summary: MoneyHelper international price formatting utility.
|
89
124
|
test_files:
|
90
125
|
- spec/money_helper_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/version_spec.rb
|