latinum 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c055e958ac724d131bdbb261f18f6f8b6e6f475a77d633710077a0722c19ffc
4
- data.tar.gz: 258a4c2c4233bc9e030a9e5cec7b685c0f7563bb012427809a6c6901067f69f1
3
+ metadata.gz: f825651126ff9e8239c2e4a07ea0da209856ab14f1934a41b976e2fae5409461
4
+ data.tar.gz: 529333c4807ca6d5a5e3b77c9b2e878e020dfbf3a1a2eb5b91ec7fa0751f0def
5
5
  SHA512:
6
- metadata.gz: cd104cf3d2664d37fde830088298544795148a782ff3ad37f9265acfbbac0d1e159d5aba27cbb8dfbac1679f25771fb0a26e902835f3b3417c465defa117d3ea
7
- data.tar.gz: 6891feee50ec8cb81c7d6f99857ad555d8ad283a1d3729efdf4ed8f92204a3699beae4ef457e06d6e905d7890f5cca6464beb4f92c552da0853682ba3e671da5
6
+ metadata.gz: '070721834d07b204257252a264584559876580f9e446b334f7df94b531515349a531d167c8b5bdd9ff6cbe82fe6ee95056e27fb31100da5d8cb54caf4c3724cd'
7
+ data.tar.gz: 6c0fd2419f7872e178f9ef0712d6192db7da08400ee5e19b1b5d2038eba131261e79a87ac4a9355288ffa08ed8c2715af34a78f17e3c56dd3adac9f453c8d8cf
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ F���{f��
2
+ � ,��\X�F����F@
3
+ K�7�i�e�g�cG����S�/�ѳ��d gS�+��d��KH�E,���x�7�c N��+�vV��cr\((\:0Ӽ%��vv��o�=g��@ݨ�\l^4fɨ_
data/lib/.DS_Store ADDED
Binary file
data/lib/latinum/bank.rb CHANGED
@@ -1,24 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all 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,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2012-2023, by Samuel Williams.
5
+ # Copyright, 2020, by Tim Craft.
22
6
 
23
7
  require 'latinum/resource'
24
8
 
@@ -61,7 +45,7 @@ module Latinum
61
45
  # Symbols and their associated priorities
62
46
  @symbols = {}
63
47
 
64
- imports.each do |resources|
48
+ imports&.each do |resources|
65
49
  import(resources)
66
50
  end
67
51
  end
@@ -124,18 +108,39 @@ module Latinum
124
108
  parts = string.strip.split(/\s+/, 2)
125
109
 
126
110
  if parts.size == 2
127
- return Resource.new(parts[0].gsub(/[^\-\.0-9]/, ''), parts[1])
111
+ return parse_named_resource(parts[1], parts[0])
128
112
  else
129
113
  # Lookup the named symbol, e.g. '$', and get the highest priority name:
130
114
  symbol = @symbols.fetch(string.gsub(/[\-\.,0-9]/, ''), []).last
131
115
 
132
116
  if symbol
133
- return Resource.new(string.gsub(/[^\-\.0-9]/, ''), symbol.last.to_s)
117
+ name = symbol.last.to_s
134
118
  elsif default_name
135
- return Resource.new(string.gsub(/[^\-\.0-9]/, ''), default_name.to_s)
119
+ name = default_name
136
120
  else
137
- raise ArgumentError.new("Could not parse #{string}, could not determine currency!")
121
+ raise ArgumentError, "Could not parse #{string}, could not determine resource name!"
138
122
  end
123
+
124
+ return parse_named_resource(name, string)
125
+ end
126
+ end
127
+
128
+ def load(input)
129
+ if input.is_a?(String)
130
+ input = input.strip
131
+ return parse(input) unless input.empty?
132
+ end
133
+ end
134
+
135
+ def dump(resource)
136
+ resource.to_s if resource
137
+ end
138
+
139
+ private def parse_named_resource(name, value)
140
+ if formatter = @formatters[name]
141
+ return Resource.new(formatter.parse(value), name)
142
+ else
143
+ raise ArgumentError, "No formatter found for #{name}!"
139
144
  end
140
145
  end
141
146
 
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all 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,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2012-2023, by Samuel Williams.
22
5
 
23
6
  require 'bigdecimal'
24
7
  require 'set'
@@ -84,6 +67,10 @@ module Latinum
84
67
  return collection
85
68
  end
86
69
 
70
+ def key?(name)
71
+ @resources.key?(name)
72
+ end
73
+
87
74
  # @returns [Resource | Nil] A resource for the specified name.
88
75
  def [] key
89
76
  if amount = @resources[key]
@@ -1,26 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # encoding: UTF-8
4
- #
5
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining a copy
8
- # of this software and associated documentation files (the "Software"), to deal
9
- # in the Software without restriction, including without limitation the rights
10
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- # copies of the Software, and to permit persons to whom the Software is
12
- # furnished to do so, subject to the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be included in
15
- # all copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2012-2023, by Samuel Williams.
24
5
 
25
6
  require 'latinum/formatters'
26
7
 
@@ -76,7 +57,7 @@ module Latinum
76
57
  :name => 'EUR',
77
58
  :description => 'Euro',
78
59
  :formatter => Formatters::DecimalCurrencyFormatter,
79
- #:delimeter => '.',
60
+ #:delimiter => '.',
80
61
  #:separator => ','
81
62
  }
82
63
 
@@ -90,6 +71,18 @@ module Latinum
90
71
  :formatter => Formatters::DecimalCurrencyFormatter
91
72
  }
92
73
 
74
+ # @name Global[:BRL]
75
+ # @attribute [Hash] The Brazilian Real configuration.
76
+ Global[:BRL] = {
77
+ :precision => 2,
78
+ :symbol => 'R$',
79
+ :name => 'BRL',
80
+ :description => 'Brazilian Real',
81
+ :formatter => Formatters::DecimalCurrencyFormatter,
82
+ :delimiter => '.',
83
+ :separator => ','
84
+ }
85
+
93
86
  # @name Global[:BTC]
94
87
  # @attribute [Hash] The Bitcoin configuration.
95
88
  Global[:BTC] = {
data/lib/latinum/error.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all 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,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2023, by Samuel Williams.
22
5
 
23
6
  module Latinum
24
7
  # Represents an error when trying to perform arithmetic on differently named resources.
@@ -1,24 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all 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,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2012-2023, by Samuel Williams.
5
+ # Copyright, 2020, by Tim Craft.
6
+ # Copyright, 2021, by Adam Daniels.
22
7
 
23
8
  module Latinum
24
9
  module Formatters
@@ -28,6 +13,12 @@ module Latinum
28
13
  @name = name
29
14
  end
30
15
 
16
+ # Parse a string into an amount.
17
+ # @returns [BigDecimal] The parsed amount.
18
+ def parse(string)
19
+ BigDecimal(string)
20
+ end
21
+
31
22
  # Formats the amount using a general notation.
32
23
  # e.g. "5.0 NZD".
33
24
  # @returns [String] The formatted string.
@@ -55,7 +46,7 @@ module Latinum
55
46
  def initialize(**options)
56
47
  @symbol = options[:symbol] || '$'
57
48
  @separator = options[:separator] || '.'
58
- @delimeter = options[:delimeter] || ','
49
+ @delimiter = options[:delimiter] || ','
59
50
  @places = options[:precision] || 2
60
51
  @zero = options[:zero] || '0'
61
52
 
@@ -66,7 +57,15 @@ module Latinum
66
57
  return amount.round(@places)
67
58
  end
68
59
 
69
- # Formats the amount using the configured symbol, separator, delimeter, and places.
60
+ # Parse a string into an amount using the configured separator and delimiter.
61
+ # @returns [BigDecimal] The parsed amount.
62
+ def parse(string)
63
+ BigDecimal(
64
+ string.gsub(/[^\-0-9#{@separator}]/, '').gsub(@separator, '.')
65
+ )
66
+ end
67
+
68
+ # Formats the amount using the configured symbol, separator, delimiter, and places.
70
69
  # e.g. "$5,000.00 NZD". Rounds the amount to the specified number of decimal places.
71
70
  # @returns [String] The formatted string.
72
71
  def format(amount, places: @places, **options)
@@ -87,7 +86,7 @@ module Latinum
87
86
  groups.unshift(integral[0...remainder]) if remainder > 0
88
87
 
89
88
  symbol = options.fetch(:symbol, @symbol)
90
- value = "#{sign}#{symbol}#{groups.join(@delimeter)}"
89
+ value = "#{sign}#{symbol}#{groups.join(@delimiter)}"
91
90
 
92
91
  name = options.fetch(:name, @name)
93
92
  suffix = name ? " #{name}" : ''
@@ -1,24 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all 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,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2012-2023, by Samuel Williams.
5
+ # Copyright, 2015, by Michael Adams.
6
+ # Copyright, 2021, by Adam Daniels.
22
7
 
23
8
  require 'bigdecimal'
24
9
  require 'bigdecimal/util'
@@ -40,12 +25,10 @@ module Latinum
40
25
  # Load a string representation of a resource.
41
26
  # @parameter string [String | Nil] e.g. "5 NZD" or nil.
42
27
  # @returns [Resource | Nil] The Resource that represents the parsed string.
43
- def self.load(string)
44
- if string
45
- # Remove any whitespaces
46
- string = string.strip
47
-
48
- parse(string) unless string.empty?
28
+ def self.load(input)
29
+ if input.is_a?(String)
30
+ input = input.strip
31
+ return parse(input) unless input.empty?
49
32
  end
50
33
  end
51
34
 
@@ -1,25 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all 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,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2012-2023, by Samuel Williams.
22
5
 
23
6
  module Latinum
24
- VERSION = "1.7.0"
7
+ VERSION = "1.8.0"
25
8
  end
data/lib/latinum.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all 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,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2012-2023, by Samuel Williams.
22
5
 
23
6
  require 'latinum/bank'
24
7
  require 'latinum/resource'
data/license.md ADDED
@@ -0,0 +1,24 @@
1
+ # MIT License
2
+
3
+ Copyright, 2012-2023, by Samuel Williams.
4
+ Copyright, 2015, by Michael Adams.
5
+ Copyright, 2020, by Tim Craft.
6
+ Copyright, 2021, by Adam Daniels.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,39 @@
1
+ # Latinum
2
+
3
+ Latinum is a library for resource and money calculations. It provides immutable {ruby Latinum::Resource} objects for dealing with quantities of named resources with an arbitrary number of decimal places, and {ruby Latinum::Bank} objects for converting resources and formatting them for output. Latinum doesn't include any global state by design and thus is ideal for integration with other frameworks/libraries.
4
+
5
+ [![Development Status](https://github.com/ioquatix/latinum/workflows/Test/badge.svg)](https://github.com/ioquatix/latinum/actions?workflow=Test)
6
+
7
+ ## Motivation
8
+
9
+ I was originally planning on using the [Money gem](https://github.com/RubyMoney/money), but it's [dependency on global state](https://github.com/RubyMoney/money/blob/39b617cca8f02c885cc8246e0aab3e9dc5f90e15/lib/money/currency.rb#L19-L21) makes it hard to use if you want to deal with money as an immutable value type.
10
+
11
+ Additionally, I wanted to support BitCoin, Japanese Yen, etc. The money gem was heavily biased towards decimal currency. It had (\~2012) [fields like `dollars` and `cents`](https://github.com/RubyMoney/money/issues/197) which don't really make sense and don't really align with the real world. These days they have fixed parts of the API, but it's a bit of a mess now, supporting both decimal and non-decimal values.
12
+
13
+ Another problem I had at the time was the [concept of zero](https://github.com/RubyMoney/money/issues/195). It should be possible to have an additive (e.g. 0) and multiplicative identity (e.g. 1) do the right thing. In fact, in Latinum, you can multiply `Latinum::Resource` instances by a scalar and get a useful result (e.g. for computing discounts).
14
+
15
+ Finally, because of the above problem, it was not obvious at the time how to sum up a collection of money instances correctly. In fact, this is still a problem and a separate gem, based on the `Latinum::Collection` concept, [was made](https://github.com/lulalala/money-collection). However, this all fits together in a rather haphazard way.
16
+
17
+ Latinum addresses all these issues. It has an immutable value type `Latinum::Resource` which has a robust definition: A value (e.g. 5.0025) and a resource name (USD). The semantics of resources are well defined without the need for "Currency" state like the symbol, how many decimal places, etc. So, it suits well for serialization into a database, and for formatting to the user, there is `Latinum::Bank` which gives you the choice of how you decide to format things or exchange them, whether you want to round something off, etc.
18
+
19
+ ## Usage
20
+
21
+ Please see the [project documentation](https://ioquatix.github.io/latinum).
22
+
23
+ ## Contributing
24
+
25
+ We welcome contributions to this project.
26
+
27
+ 1. Fork it.
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
30
+ 4. Push to the branch (`git push origin my-new-feature`).
31
+ 5. Create new Pull Request.
32
+
33
+ ### Developer Certificate of Origin
34
+
35
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
36
+
37
+ ### Contributor Covenant
38
+
39
+ This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,77 +1,54 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latinum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Tim Craft
9
+ - Adam Daniels
10
+ - Michael Adams
8
11
  autorequire:
9
12
  bindir: bin
10
- cert_chain: []
11
- date: 2021-03-14 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: covered
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.4'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.4'
13
+ cert_chain:
14
+ - |
15
+ -----BEGIN CERTIFICATE-----
16
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
17
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
18
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
19
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
20
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
21
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
22
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
23
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
24
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
25
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
26
+ XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
27
+ RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
28
+ tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
29
+ zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
30
+ xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
31
+ BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
32
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
33
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
34
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
35
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
36
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
37
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
38
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
39
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
40
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
41
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
42
+ -----END CERTIFICATE-----
43
+ date: 2023-11-06 00:00:00.000000000 Z
44
+ dependencies: []
69
45
  description:
70
46
  email:
71
47
  executables: []
72
48
  extensions: []
73
49
  extra_rdoc_files: []
74
50
  files:
51
+ - lib/.DS_Store
75
52
  - lib/latinum.rb
76
53
  - lib/latinum/bank.rb
77
54
  - lib/latinum/collection.rb
@@ -80,6 +57,8 @@ files:
80
57
  - lib/latinum/formatters.rb
81
58
  - lib/latinum/resource.rb
82
59
  - lib/latinum/version.rb
60
+ - license.md
61
+ - readme.md
83
62
  homepage: https://github.com/ioquatix/latinum
84
63
  licenses:
85
64
  - MIT
@@ -93,14 +72,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
72
  requirements:
94
73
  - - ">="
95
74
  - !ruby/object:Gem::Version
96
- version: '2.5'
75
+ version: '3.0'
97
76
  required_rubygems_version: !ruby/object:Gem::Requirement
98
77
  requirements:
99
78
  - - ">="
100
79
  - !ruby/object:Gem::Version
101
80
  version: '0'
102
81
  requirements: []
103
- rubygems_version: 3.1.2
82
+ rubygems_version: 3.4.10
104
83
  signing_key:
105
84
  specification_version: 4
106
85
  summary: Provides immutable resource and money computations.
metadata.gz.sig ADDED
Binary file