minting 0.3.0 → 0.3.2
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 +26 -11
- data/lib/minting/mint/registry.rb +6 -2
- data/lib/minting/money/allocation.rb +1 -1
- data/lib/minting/money/arithmetics.rb +1 -1
- data/lib/minting/money/comparable.rb +5 -5
- data/lib/minting/money/money.rb +8 -2
- data/lib/minting/version.rb +1 -1
- data/minting.gemspec +2 -2
- metadata +4 -8
- data/lib/minting/currency.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 197525ac986a8283ad9caf5fbc1c828b3c41c2da5a544b398357dccb8d6de430
|
4
|
+
data.tar.gz: ceed85f0f3617e83a1c50f43d4fb0a3f558f335af2f91c78c751278ef3cb0e23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 958922e3db6e4ee1a53a4e42feed3a1a6fb41e129ca50b7b2335b713e689d0c5172ba7d65f6b4e37f82cb6934f39a4a03f5a8d9bf55e2e5842f68caf894e9c98
|
7
|
+
data.tar.gz: 593f757a56e95667a80af223a8dde7c55771cbd24529a04625372c78d2266f7a86d0117b45a62bbf005aed6cd5434e33ece7ac898baee4609a73badf4add448e
|
data/README.md
CHANGED
@@ -6,21 +6,36 @@ Work in progress, please wait release 1.0.0
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Option 1: Via bundler command
|
10
|
+
|
11
|
+
```shell
|
12
|
+
bundle add minting
|
13
|
+
bundle install
|
14
|
+
```
|
15
|
+
|
16
|
+
Option 2: add the line below to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'minting'
|
20
|
+
```
|
21
|
+
|
22
|
+
or, if you want latest development version from Github
|
10
23
|
|
11
24
|
```ruby
|
12
25
|
gem 'minting', git: 'https://github.com/gferraz/minting.git'
|
13
26
|
```
|
14
27
|
|
15
|
-
|
28
|
+
and execute:
|
16
29
|
|
17
|
-
|
30
|
+
```shell
|
31
|
+
bundle install
|
32
|
+
```
|
18
33
|
|
19
|
-
|
34
|
+
Option3: Install it yourself with:
|
20
35
|
|
21
|
-
|
22
|
-
|
23
|
-
|
36
|
+
```shell
|
37
|
+
gem install minting
|
38
|
+
````
|
24
39
|
|
25
40
|
## Usage
|
26
41
|
|
@@ -52,7 +67,7 @@ price.to_s(format: '%<symbol>s%<amount>+f') #=> "$+9.99",
|
|
52
67
|
(-price).to_s(format: '%<amount>f') #=> "-9.99",
|
53
68
|
|
54
69
|
# Format with padding
|
55
|
-
price_in_euros =
|
70
|
+
price_in_euros = Mint.money(12.34, 'EUR')
|
56
71
|
|
57
72
|
price.to_s(format: '--%<amount>7d') #=> "-- 9"
|
58
73
|
price.to_s(format: ' %<amount>10f %<currency>s') #=> " 9.99 USD"
|
@@ -72,21 +87,21 @@ ten_dollars.split(7) #=> [[USD 1.42], [USD 1.43], [USD 1.43], [USD 1.43], [USD 1
|
|
72
87
|
ten_dollars.allocate([1, 2, 3]) #=> [[USD 1.67], [USD 3.33], [USD 5.00]]
|
73
88
|
|
74
89
|
# Numeric refinements
|
75
|
-
|
90
|
+
using Mint
|
76
91
|
|
77
92
|
1.dollar == Mint.money(1, 'USD') #=> true
|
78
93
|
3.euros == Mint.money(2, 'EUR') #=> true
|
79
94
|
4.mint('USD') == 4.dollars #=> true
|
80
95
|
4.to_money('USD') == 4.dollars #=> true
|
96
|
+
|
81
97
|
```
|
82
98
|
|
83
99
|
## Release 1.0 Plan
|
84
100
|
|
85
|
-
- Rails
|
86
101
|
- Localization: I18n
|
87
102
|
- Arithmetics: div, mod
|
88
103
|
- Mint.parse
|
89
104
|
|
90
105
|
## Contributing
|
91
106
|
|
92
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/gferraz/minting
|
107
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/gferraz/minting>.
|
@@ -3,7 +3,11 @@
|
|
3
3
|
# :nodoc
|
4
4
|
module Mint
|
5
5
|
def self.money(amount, currency_code)
|
6
|
-
|
6
|
+
currency = currency(currency_code)
|
7
|
+
return Money.new(amount, currency) if currency
|
8
|
+
|
9
|
+
available = currencies.keys.join(', ')
|
10
|
+
raise ArgumentError, "Currency [#{currency_code}] not registered. Available: #{available}"
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.currency(currency)
|
@@ -41,7 +45,7 @@ module Mint
|
|
41
45
|
@currencies ||= {
|
42
46
|
'AUD' => Currency.new('AUD', subunit: 2, symbol: '$'),
|
43
47
|
'BRL' => Currency.new('BRL', subunit: 2, symbol: 'R$'),
|
44
|
-
'CAD' => Currency.new('CAD', subunit: 2, symbol: '
|
48
|
+
'CAD' => Currency.new('CAD', subunit: 2, symbol: '$'),
|
45
49
|
'CHF' => Currency.new('CHF', subunit: 2, symbol: 'Fr'),
|
46
50
|
'CNY' => Currency.new('CNY', subunit: 2, symbol: '¥'),
|
47
51
|
'EUR' => Currency.new('EUR', subunit: 2, symbol: '€'),
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Mint
|
4
4
|
# :nodoc
|
5
|
-
#
|
5
|
+
# Comparison methods
|
6
6
|
class Money
|
7
7
|
include Comparable
|
8
8
|
|
@@ -16,12 +16,12 @@ module Mint
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# @example
|
19
|
-
# two_usd == Mint.money(2r,
|
20
|
-
# two_usd > 0
|
21
|
-
# two_usd > Mint.money(
|
19
|
+
# two_usd == Mint.money(2r, 'USD']) #=> [$ 2.00]
|
20
|
+
# two_usd > 0 #=> true
|
21
|
+
# two_usd > Mint.money(2, 'USD']) #=> true
|
22
22
|
# two_usd > 1
|
23
23
|
# => TypeError: [$ 2.00] can't be compared to 1
|
24
|
-
# two_usd > Mint.money(2,
|
24
|
+
# two_usd > Mint.money(2, 'BRL'])
|
25
25
|
# => TypeError: [$ 2.00] can't be compared to [R$ 2.00]
|
26
26
|
#
|
27
27
|
def <=>(other)
|
data/lib/minting/money/money.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Mint
|
4
|
-
# Money is a value object for monetary values
|
5
|
-
# Money is immutable
|
6
4
|
class Money
|
7
5
|
DEFAULT_FORMAT = '%<symbol>s%<amount>f'
|
8
6
|
|
9
7
|
attr_reader :amount, :currency
|
10
8
|
|
9
|
+
# Creates a new Money immutable object with the specified amount and currency
|
10
|
+
# @param amount [Numeric] The monetary amount
|
11
|
+
# @param currency [Currency] The currency object
|
12
|
+
# @raise [ArgumentError] If amount is not numeric or currency is invalid
|
11
13
|
def initialize(amount, currency)
|
12
14
|
raise ArgumentError, 'amount must be Numeric' unless amount.is_a?(Numeric)
|
13
15
|
|
@@ -24,6 +26,10 @@ module Mint
|
|
24
26
|
currency.code
|
25
27
|
end
|
26
28
|
|
29
|
+
# Returns a new Money object with the specified amount, or self if unchanged
|
30
|
+
# @param new_amount [Numeric] The new amount
|
31
|
+
# @return [Money] A new Money object or self
|
32
|
+
|
27
33
|
def mint(new_amount)
|
28
34
|
new_amount.to_r == amount ? self : Money.new(new_amount, currency)
|
29
35
|
end
|
data/lib/minting/version.rb
CHANGED
data/minting.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
# Prevent pushing this gem to RubyGems.org.
|
16
16
|
# To allow pushes either set the 'allowed_push_host' to allow pushing to
|
17
17
|
# a single host or delete this section to allow pushing to any host.
|
18
|
-
raise 'RubyGems 3.
|
18
|
+
raise 'RubyGems 3.2 or newer is required' unless s.respond_to?(:metadata)
|
19
19
|
|
20
20
|
s.metadata = {
|
21
21
|
'bug_tracker_uri' => "#{s.homepage}/issues",
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
'rubygems_mfa_required' => 'true'
|
27
27
|
}
|
28
28
|
|
29
|
-
s.required_ruby_version = '>= 3.
|
29
|
+
s.required_ruby_version = '>= 3.2.0'
|
30
30
|
|
31
31
|
s.files = Dir.glob('{bin,doc,lib}/**/*')
|
32
32
|
s.files += %w[minting.gemspec Rakefile README.md]
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilson Ferraz
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: Library to manipulate currency values
|
14
13
|
email: []
|
@@ -21,7 +20,6 @@ files:
|
|
21
20
|
- bin/console
|
22
21
|
- bin/setup
|
23
22
|
- lib/minting.rb
|
24
|
-
- lib/minting/currency.rb
|
25
23
|
- lib/minting/mint.rb
|
26
24
|
- lib/minting/mint/currency.rb
|
27
25
|
- lib/minting/mint/refinements.rb
|
@@ -45,7 +43,6 @@ metadata:
|
|
45
43
|
source_code_uri: https://github.com/gferraz/minting
|
46
44
|
allowed_push_host: https://rubygems.org
|
47
45
|
rubygems_mfa_required: 'true'
|
48
|
-
post_install_message:
|
49
46
|
rdoc_options: []
|
50
47
|
require_paths:
|
51
48
|
- lib
|
@@ -53,15 +50,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
50
|
requirements:
|
54
51
|
- - ">="
|
55
52
|
- !ruby/object:Gem::Version
|
56
|
-
version: 3.
|
53
|
+
version: 3.2.0
|
57
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
55
|
requirements:
|
59
56
|
- - ">="
|
60
57
|
- !ruby/object:Gem::Version
|
61
58
|
version: '0'
|
62
59
|
requirements: []
|
63
|
-
rubygems_version: 3.
|
64
|
-
signing_key:
|
60
|
+
rubygems_version: 3.7.1
|
65
61
|
specification_version: 4
|
66
62
|
summary: Library to manipulate currency values
|
67
63
|
test_files: []
|
data/lib/minting/currency.rb
DELETED