minting 0.3.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3727b084cc73e39f8fb332b083cf94a4c3fb903f616afa18023f0187e713634c
4
- data.tar.gz: cd3ad31a95c5f18b6dc8af91d66dd9e25ec87a5efcaf6b4d6a2203e6a2a15764
3
+ metadata.gz: 197525ac986a8283ad9caf5fbc1c828b3c41c2da5a544b398357dccb8d6de430
4
+ data.tar.gz: ceed85f0f3617e83a1c50f43d4fb0a3f558f335af2f91c78c751278ef3cb0e23
5
5
  SHA512:
6
- metadata.gz: da5ec1aa13bbeedc59d38a38c8fb0c6939253f6aa3960fb5beb64501e6660c16586b3fe1f6f03d54c1771cd2b5b78f39d92087070920b8694dfcbaccf75a99d4
7
- data.tar.gz: 9cc380513733e3f9c9db95225283c82b6c1073ce9a1d4b01b606673bd1d41fc1412fc79035ab5ed823fc80b28baa8cafbf6685e4bbd06c6817080e64ff498815
6
+ metadata.gz: 958922e3db6e4ee1a53a4e42feed3a1a6fb41e129ca50b7b2335b713e689d0c5172ba7d65f6b4e37f82cb6934f39a4a03f5a8d9bf55e2e5842f68caf894e9c98
7
+ data.tar.gz: 593f757a56e95667a80af223a8dde7c55771cbd24529a04625372c78d2266f7a86d0117b45a62bbf005aed6cd5434e33ece7ac898baee4609a73badf4add448e
data/README.md CHANGED
@@ -67,7 +67,7 @@ price.to_s(format: '%<symbol>s%<amount>+f') #=> "$+9.99",
67
67
  (-price).to_s(format: '%<amount>f') #=> "-9.99",
68
68
 
69
69
  # Format with padding
70
- price_in_euros = euro.money(12.34, 'EUR')
70
+ price_in_euros = Mint.money(12.34, 'EUR')
71
71
 
72
72
  price.to_s(format: '--%<amount>7d') #=> "-- 9"
73
73
  price.to_s(format: ' %<amount>10f %<currency>s') #=> " 9.99 USD"
@@ -87,7 +87,7 @@ ten_dollars.split(7) #=> [[USD 1.42], [USD 1.43], [USD 1.43], [USD 1.43], [USD 1
87
87
  ten_dollars.allocate([1, 2, 3]) #=> [[USD 1.67], [USD 3.33], [USD 5.00]]
88
88
 
89
89
  # Numeric refinements
90
- uning Mint
90
+ using Mint
91
91
 
92
92
  1.dollar == Mint.money(1, 'USD') #=> true
93
93
  3.euros == Mint.money(2, 'EUR') #=> true
@@ -4,9 +4,10 @@
4
4
  module Mint
5
5
  def self.money(amount, currency_code)
6
6
  currency = currency(currency_code)
7
- raise ArgumentError, "Currency [#{currency_code}] no registered" unless currency
7
+ return Money.new(amount, currency) if currency
8
8
 
9
- Money.new(amount, currency)
9
+ available = currencies.keys.join(', ')
10
+ raise ArgumentError, "Currency [#{currency_code}] not registered. Available: #{available}"
10
11
  end
11
12
 
12
13
  def self.currency(currency)
@@ -44,7 +45,7 @@ module Mint
44
45
  @currencies ||= {
45
46
  'AUD' => Currency.new('AUD', subunit: 2, symbol: '$'),
46
47
  'BRL' => Currency.new('BRL', subunit: 2, symbol: 'R$'),
47
- 'CAD' => Currency.new('CAD', subunit: 2, symbol: 'R$'),
48
+ 'CAD' => Currency.new('CAD', subunit: 2, symbol: '$'),
48
49
  'CHF' => Currency.new('CHF', subunit: 2, symbol: 'Fr'),
49
50
  'CNY' => Currency.new('CNY', subunit: 2, symbol: '¥'),
50
51
  'EUR' => Currency.new('EUR', subunit: 2, symbol: '€'),
@@ -16,7 +16,7 @@ module Mint
16
16
  def split(quantity)
17
17
  unless quantity.positive? && quantity.integer?
18
18
  raise ArgumentError,
19
- 'quantitity must be an integer > 0'
19
+ 'quantity must be an integer > 0'
20
20
  end
21
21
 
22
22
  fraction = self / quantity
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Mint
4
4
  # :nodoc
5
- # Arithmetic funcions for money ojects
5
+ # Arithmetic functions for money objects
6
6
  class Money
7
7
  def abs
8
8
  mint(amount.abs)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Mint
4
4
  # :nodoc
5
- # Comparision methods
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, Currency['USD']) #=> [$ 2.00]
20
- # two_usd > 0 #=> true
21
- # two_usd > Mint.money(1r, Currency['USD']) #=> true
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, Currency['BRL'])
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Minting
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.3.2'.freeze
3
3
  end
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.0 or newer is required' unless s.respond_to?(:metadata)
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.0.0'
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.1
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: 2024-05-25 00:00:00.000000000 Z
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.0.0
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.5.10
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: []
@@ -1,2 +0,0 @@
1
- require 'minting/currency/mint_currency'
2
- require 'minting/currency/currency'