minting 1.6.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +50 -2
- data/Rakefile +13 -3
- data/doc/Mint/Currency.html +993 -0
- data/doc/Mint/CurrencyRegistry.html +511 -0
- data/doc/Mint/Money.html +3856 -0
- data/doc/Mint/UnknownCurrency.html +136 -0
- data/doc/Mint.html +886 -0
- data/doc/Minting.html +142 -0
- data/doc/_index.html +158 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +206 -0
- data/doc/css/style.css +1089 -0
- data/doc/file.README.html +278 -0
- data/doc/file_list.html +59 -0
- data/doc/frames.html +22 -0
- data/doc/index.html +278 -0
- data/doc/js/app.js +801 -0
- data/doc/js/full_list.js +334 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +510 -0
- data/doc/top-level-namespace.html +143 -0
- data/lib/minting/mint/aliases.rb +7 -0
- data/lib/minting/mint/currency/currency_registry.rb +1 -1
- data/lib/minting/mint/dsl/range.rb +54 -0
- data/lib/minting/mint/{refinements.rb → dsl/refinements.rb} +4 -12
- data/lib/minting/mint/dsl/top_level.rb +14 -0
- data/lib/minting/mint/mint.rb +2 -2
- data/lib/minting/mint/parser.rb +16 -9
- data/lib/minting/mint.rb +3 -1
- data/lib/minting/money/allocation.rb +14 -14
- data/lib/minting/money/arithmetics.rb +5 -5
- data/lib/minting/money/coercion.rb +8 -11
- data/lib/minting/money/formatting.rb +23 -28
- data/lib/minting/version.rb +1 -1
- data/minting.gemspec +5 -2
- metadata +32 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 005a740f595e3f1b579b2108feb4cd742706588a75b1df41179775d311fb002e
|
|
4
|
+
data.tar.gz: b1c2d55e378cca46adde3e6edd7253bb0914707768c19fd00e568288921540ff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 48f40d6cceeb16d9ffc357297dae0961ba0473f4d9ed1271ac6e144a0a468b42dd8a553b661485317eba56d88665b08b1302c4620af1a58bb6f07ab9aa996da3
|
|
7
|
+
data.tar.gz: bc77e69b3e39d3bde0ebb47e60bb1225d0a9062e2a1f201924c3e32924ad65711c28ef492ac4c5d63b06bb376510d07e7d2d69a3efbc17805e89d703c3c15812
|
data/README.md
CHANGED
|
@@ -16,6 +16,11 @@ Fast, precise, and developer-friendly money handling for Ruby.
|
|
|
16
16
|
|
|
17
17
|
**Rails**? Use the [minting-rails](https://github.com/gferraz/minting-rails) companion gem
|
|
18
18
|
|
|
19
|
+
## Resources
|
|
20
|
+
|
|
21
|
+
- [API Documentation](https://www.rubydoc.info/gems/minting/frames)
|
|
22
|
+
- [Git Repository](https://github.com/gferraz/minting)
|
|
23
|
+
|
|
19
24
|
## Quick start
|
|
20
25
|
|
|
21
26
|
```ruby
|
|
@@ -185,6 +190,49 @@ Option 3: Install it yourself with:
|
|
|
185
190
|
gem install minting
|
|
186
191
|
```
|
|
187
192
|
|
|
193
|
+
## Configuration
|
|
194
|
+
|
|
195
|
+
### Optional top‑level `Money` and `Currency`
|
|
196
|
+
|
|
197
|
+
By default, Minting keeps everything namespaced under `Mint`:
|
|
198
|
+
|
|
199
|
+
```ruby
|
|
200
|
+
price = Mint::Money.create(10, "USD")
|
|
201
|
+
currency = Mint::Currency.new(code: "USD", symbol: "$", subunit: 2, priority: 0)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
To avoid polluting the global namespace (and to coexist nicely with other gems), **Minting dont automatically defines `Money` or `Currency` at the top level automatically**.
|
|
205
|
+
|
|
206
|
+
If you prefer the shorter `Money` / `Currency` constants in your application code, you can opt in explicitly.
|
|
207
|
+
|
|
208
|
+
There are two ways to enable shorter constants:
|
|
209
|
+
|
|
210
|
+
1. Require dsl in your app
|
|
211
|
+
|
|
212
|
+
```ruby
|
|
213
|
+
require "minting"
|
|
214
|
+
require "minting/dsl" # opt‑in top‑level Money / Currency
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
2. Call a configuration method
|
|
218
|
+
|
|
219
|
+
```ruby
|
|
220
|
+
Minting.use_top_level_constants!
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
After this, you can use:
|
|
224
|
+
|
|
225
|
+
```ruby
|
|
226
|
+
price = Money.create(10, "USD") # equivalent to Mint::Money.create
|
|
227
|
+
tax = Money.money(2.50, "USD") # via Mint.money, still available
|
|
228
|
+
cur = Currency.new(code: "EUR", symbol: "€", subunit: 2, priority: 0)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
#### When to use this
|
|
232
|
+
|
|
233
|
+
- **Good fit:** application code, especially in Rails apps, where `Money` reads nicely in models and views.
|
|
234
|
+
- **Not recommended:** reusable gems/libraries. In that case, stick to the namespaced API (`Mint::Money`, `Mint::Currency`) to avoid conflicts with other libraries.
|
|
235
|
+
|
|
188
236
|
## Parsing strings
|
|
189
237
|
|
|
190
238
|
```ruby
|
|
@@ -202,9 +250,9 @@ Mint.parse('USD 1,234.56') #=> [USD 1234.56]
|
|
|
202
250
|
|
|
203
251
|
## Roadmap
|
|
204
252
|
|
|
205
|
-
-
|
|
253
|
+
- Add support to configure thousand and decimal separators in parse (evaluating)
|
|
206
254
|
- Localization (I18n-aware formatting)
|
|
207
|
-
- Basic exchange-rate conversions
|
|
255
|
+
- Basic exchange-rate conversions - infrastructure only, not integrations yet
|
|
208
256
|
|
|
209
257
|
## Contributing
|
|
210
258
|
|
data/Rakefile
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
require 'bundler/audit/task'
|
|
1
2
|
require 'bundler/gem_tasks'
|
|
2
|
-
require 'rubocop/rake_task'
|
|
3
3
|
require 'rake/testtask'
|
|
4
|
+
require 'rubocop/rake_task'
|
|
5
|
+
require 'rubycritic/rake_task'
|
|
4
6
|
require 'yard'
|
|
5
7
|
|
|
6
8
|
CLOBBER.include %w[doc/css doc/js doc/Mint doc/*.html tmp .yardoc]
|
|
@@ -37,11 +39,19 @@ Rake::TestTask.new('bench:competitive') do |t|
|
|
|
37
39
|
t.pattern = 'test/performance/competitive/**/*_benchmark.rb'
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
Bundler::Audit::Task.new
|
|
43
|
+
|
|
44
|
+
RuboCop::RakeTask.new(:cop) do |task|
|
|
45
|
+
task.patterns = ['lib']
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
RubyCritic::RakeTask.new do |task|
|
|
49
|
+
task.name = 'critic'
|
|
50
|
+
end
|
|
41
51
|
|
|
42
52
|
YARD::Rake::YardocTask.new do |t|
|
|
43
53
|
t.files = ['lib/**/*.rb']
|
|
44
|
-
t.options = ['-o doc
|
|
54
|
+
#t.options = ['-o doc'] # Place the documentos in doc/api
|
|
45
55
|
t.stats_options = ['--list-undoc']
|
|
46
56
|
end
|
|
47
57
|
|