spook_and_puff_money 1.0.0 → 1.0.3
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 +5 -5
- data/MIT-LICENSE +1 -1
- data/README.md +2 -2
- data/lib/spook_and_puff/money.rb +15 -5
- metadata +15 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f66498f529e17e83990cb37a1ffb2080750a3e003d8208c03a23d0207eb3f9d4
|
4
|
+
data.tar.gz: f11c467614ae5db0a35c469828813245d8a1ae6a0164712d96f6eaa0102b3df9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33d11ccff4c6d06fe249ad43ddf49957ee7e9baafaff9c7837a3b8f2f78ed32a6049abafdcad71e71897d59666c79a74483ce39f120cdb87539092a00c6f1208
|
7
|
+
data.tar.gz: 41504d8bca3f596537226e83dd6b899e48595c45c748035f027db09d0b734b8c5fadfffd470886f22513f33b61ba074b612387cd6362fab4ef71f700c2bbaa1b
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SpookAndPuff::Money
|
2
2
|
|
3
|
-
This is yet another Ruby class made to represent money. This one is dead simple. It doesn't integrate with any frameworks, it simply enforces precison by ensuring all operands -- for methods like +, -, / etc. -- are BigDecimals.
|
3
|
+
This is yet another Ruby class made to represent money. This one is dead simple. It doesn't integrate with any frameworks, it simply enforces precison by ensuring all operands -- for methods like +, -, / etc. -- are BigDecimals.
|
4
4
|
|
5
5
|
It also provides a few other conveniences like formatting.
|
6
6
|
|
@@ -62,7 +62,7 @@ The argument types of each method is documented, so don't forget to have a look
|
|
62
62
|
|
63
63
|
# SpookAndPuff::MoneyAttributes
|
64
64
|
|
65
|
-
This is a module provided as a convenience for working with ActiveRecord models. It is not required by default when using this gem, instead you must require it separately.
|
65
|
+
This is a module provided as a convenience for working with ActiveRecord models. It is not required by default when using this gem, instead you must require it separately.
|
66
66
|
|
67
67
|
Assuming you have the gem installed:
|
68
68
|
|
data/lib/spook_and_puff/money.rb
CHANGED
@@ -9,6 +9,8 @@ module SpookAndPuff
|
|
9
9
|
class Money
|
10
10
|
include Comparable
|
11
11
|
|
12
|
+
NUMBER_OF_CENTS = 100.freeze
|
13
|
+
|
12
14
|
# Stores the raw BigDecimal instance that a Money instance wraps.
|
13
15
|
attr_reader :raw
|
14
16
|
|
@@ -23,11 +25,19 @@ module SpookAndPuff
|
|
23
25
|
@raw = case value
|
24
26
|
when SpookAndPuff::Money then value.raw
|
25
27
|
when BigDecimal then value
|
26
|
-
when String then BigDecimal
|
28
|
+
when String then BigDecimal(value.gsub(/\$/, ''))
|
27
29
|
else raise TypeError.new("Money can only be initalized with a BigDecimal or String not #{value.class}.")
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
33
|
+
# Initialize a money instance by providing an number of cents
|
34
|
+
#
|
35
|
+
# @return SpookAndPuff::Money
|
36
|
+
def self.cents(cents)
|
37
|
+
raise TypeError.new('SpookAndPuff::Money#cents expects a number of cents') unless cents.is_a? Numeric
|
38
|
+
new((cents / NUMBER_OF_CENTS).to_s)
|
39
|
+
end
|
40
|
+
|
31
41
|
# A convenience method which returns an instance initalized to zero.
|
32
42
|
#
|
33
43
|
# @return SpookAndPuff::Money
|
@@ -125,7 +135,7 @@ module SpookAndPuff
|
|
125
135
|
#
|
126
136
|
# @return BigDecimal
|
127
137
|
def cents
|
128
|
-
@raw * BigDecimal
|
138
|
+
@raw * BigDecimal('100')
|
129
139
|
end
|
130
140
|
|
131
141
|
# Returns the raw BigDecimal value.
|
@@ -171,7 +181,7 @@ module SpookAndPuff
|
|
171
181
|
#
|
172
182
|
# @raise TypeError
|
173
183
|
def percent(percentage)
|
174
|
-
Money.new(@raw * (coerce(percentage) / BigDecimal
|
184
|
+
Money.new(@raw * (coerce(percentage) / BigDecimal('100')))
|
175
185
|
end
|
176
186
|
|
177
187
|
# Calculates the proportion of the provided amount as a percentage.
|
@@ -253,8 +263,8 @@ module SpookAndPuff
|
|
253
263
|
def coerce(other)
|
254
264
|
case other
|
255
265
|
when BigDecimal then other
|
256
|
-
when String then BigDecimal
|
257
|
-
when Integer, Fixnum, Bignum then BigDecimal
|
266
|
+
when String then BigDecimal(other)
|
267
|
+
when Integer, Fixnum, Bignum then BigDecimal(other.to_s)
|
258
268
|
else raise TypeError
|
259
269
|
end
|
260
270
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spook_and_puff_money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Luke Sutton
|
8
7
|
- Ben Hull
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-12-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
@@ -31,31 +30,31 @@ dependencies:
|
|
31
30
|
requirements:
|
32
31
|
- - '='
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.
|
33
|
+
version: 0.9.20
|
35
34
|
type: :development
|
36
35
|
prerelease: false
|
37
36
|
version_requirements: !ruby/object:Gem::Requirement
|
38
37
|
requirements:
|
39
38
|
- - '='
|
40
39
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.
|
40
|
+
version: 0.9.20
|
42
41
|
- !ruby/object:Gem::Dependency
|
43
42
|
name: redcarpet
|
44
43
|
requirement: !ruby/object:Gem::Requirement
|
45
44
|
requirements:
|
46
45
|
- - '='
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
47
|
+
version: 3.5.1
|
49
48
|
type: :development
|
50
49
|
prerelease: false
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
52
51
|
requirements:
|
53
52
|
- - '='
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
56
|
-
description:
|
54
|
+
version: 3.5.1
|
55
|
+
description:
|
57
56
|
email:
|
58
|
-
-
|
57
|
+
- gems@companionstudio.com.au
|
59
58
|
executables: []
|
60
59
|
extensions: []
|
61
60
|
extra_rdoc_files: []
|
@@ -64,10 +63,11 @@ files:
|
|
64
63
|
- README.md
|
65
64
|
- lib/spook_and_puff/money.rb
|
66
65
|
- lib/spook_and_puff/money_attributes.rb
|
67
|
-
homepage:
|
68
|
-
licenses:
|
66
|
+
homepage: https://github.com/companionstudio/money
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
69
|
metadata: {}
|
70
|
-
post_install_message:
|
70
|
+
post_install_message:
|
71
71
|
rdoc_options: []
|
72
72
|
require_paths:
|
73
73
|
- lib
|
@@ -82,10 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
|
86
|
-
|
87
|
-
signing_key:
|
85
|
+
rubygems_version: 3.0.8
|
86
|
+
signing_key:
|
88
87
|
specification_version: 4
|
89
88
|
summary: A simple money class.
|
90
89
|
test_files: []
|
91
|
-
has_rdoc:
|