monies 1.0.1 → 1.1.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -0
  3. data/lib/monies.rb +24 -0
  4. data/monies.gemspec +2 -1
  5. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ffee4b91733b331056188aef0f3576b9e90fc16847f91174749f7ffc154e7ff
4
- data.tar.gz: bac13063005ebde101cf5faa4405fcfe48c1107bb10e6568ae35fe9c51191ce7
3
+ metadata.gz: 736b4a239f90fc0979d0b7a0ad4ab2b55986a6d9b371420ab250d8c6c3cb6e5c
4
+ data.tar.gz: 9a4127b66e6321c91baf2f39200584fab7fbedb3d653278de6beb6c995664065
5
5
  SHA512:
6
- metadata.gz: e7a50b0b8c9584a16dc75be18bac0e54f706028cda755d501e8e91f3a2c84487b4b4763ac6ba651c36ccb70b2b275baa445983133982d926efb299653989611b
7
- data.tar.gz: 9a1f89469a73048e45e55cd6db7e3a93b4e2cfc99a9a5dbf6d247e56ee89f68ddea4bd76b66d819e8e844f5967911878a88c7a12996743923416e475d56db57d
6
+ metadata.gz: 37bcf8de107b4d63468a8b717ccc2bf3b901128a89f4b2a394d8ce24b33b3d12317fb2a66978163ec7625af29edd6748435d7a2016aa4ea701281a5efb3a9170
7
+ data.tar.gz: c66aa18d837262bfd5e0072dc566fa0bd2a044a14ead9a46a11cbbb6338a5a38c3f7a659d545d2cc9cf75417eaea0eeaf6ef30850b19f6f851801d7d86f8d4c9
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # monies
2
2
 
3
+ ![Gem Version](https://badge.fury.io/rb/monies.svg)
4
+ ![Test Status](https://github.com/readysteady/monies/actions/workflows/test.yml/badge.svg)
5
+
6
+
3
7
  Ruby gem for representing monetary values.
4
8
 
5
9
  Pure Ruby—compatible with MRI/CRuby, JRuby, TruffleRuby, and Natalie.
@@ -76,6 +80,12 @@ the maximum number of decimal places you want:
76
80
  Monies(1, 'USD').div(9, 100)
77
81
  ```
78
82
 
83
+ Use the #allocate method to split an amount into a number of smaller amounts:
84
+
85
+ ```ruby
86
+ installments = Monies(1, 'USD').allocate(3, 2)
87
+ ```
88
+
79
89
 
80
90
  ## Currency conversion
81
91
 
data/lib/monies.rb CHANGED
@@ -195,6 +195,22 @@ class Monies
195
195
  self.class.new(@value.abs, @scale, @currency)
196
196
  end
197
197
 
198
+ def allocate(n, digits)
199
+ unless n.is_a?(Integer) && n >= 1
200
+ raise ArgumentError, 'n must be greater than or equal to 1'
201
+ end
202
+
203
+ quotient = (self / n).truncate(digits)
204
+
205
+ remainder = self - quotient * n
206
+
207
+ array = Array.new(n) { quotient }
208
+
209
+ array[-1] += remainder unless remainder.zero?
210
+
211
+ array
212
+ end
213
+
198
214
  def ceil(digits = 0)
199
215
  round(digits, :ceil)
200
216
  end
@@ -271,10 +287,18 @@ class Monies
271
287
  raise TypeError, "#{self.class} can't be divided by #{other.class}"
272
288
  end
273
289
 
290
+ def fix
291
+ self.class.new(@value / (BASE ** @scale), 0, @currency)
292
+ end
293
+
274
294
  def floor(digits = 0)
275
295
  round(digits, :floor)
276
296
  end
277
297
 
298
+ def frac
299
+ self - fix
300
+ end
301
+
278
302
  def inspect
279
303
  "#<#{self.class.name}: #{Monies::Digits.dump(self)} #{@currency}>"
280
304
  end
data/monies.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'monies'
3
- s.version = '1.0.1'
3
+ s.version = '1.1.0'
4
4
  s.license = 'LGPL-3.0'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Tim Craft']
@@ -15,5 +15,6 @@ Gem::Specification.new do |s|
15
15
  'homepage' => 'https://github.com/readysteady/monies',
16
16
  'source_code_uri' => 'https://github.com/readysteady/monies',
17
17
  'bug_tracker_uri' => 'https://github.com/readysteady/monies/issues',
18
+ 'changelog_uri' => 'https://github.com/readysteady/monies/blob/main/CHANGES.md'
18
19
  }
19
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monies
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-05 00:00:00.000000000 Z
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem for representing monetary values
14
14
  email:
@@ -35,6 +35,7 @@ metadata:
35
35
  homepage: https://github.com/readysteady/monies
36
36
  source_code_uri: https://github.com/readysteady/monies
37
37
  bug_tracker_uri: https://github.com/readysteady/monies/issues
38
+ changelog_uri: https://github.com/readysteady/monies/blob/main/CHANGES.md
38
39
  post_install_message:
39
40
  rdoc_options: []
40
41
  require_paths: