latinum 1.6.0 → 1.7.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.
- checksums.yaml +4 -4
- data/lib/latinum/formatters.rb +5 -5
- data/lib/latinum/resource.rb +1 -1
- data/lib/latinum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c055e958ac724d131bdbb261f18f6f8b6e6f475a77d633710077a0722c19ffc
|
4
|
+
data.tar.gz: 258a4c2c4233bc9e030a9e5cec7b685c0f7563bb012427809a6c6901067f69f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd104cf3d2664d37fde830088298544795148a782ff3ad37f9265acfbbac0d1e159d5aba27cbb8dfbac1679f25771fb0a26e902835f3b3417c465defa117d3ea
|
7
|
+
data.tar.gz: 6891feee50ec8cb81c7d6f99857ad555d8ad283a1d3729efdf4ed8f92204a3699beae4ef457e06d6e905d7890f5cca6464beb4f92c552da0853682ba3e671da5
|
data/lib/latinum/formatters.rb
CHANGED
@@ -55,7 +55,7 @@ module Latinum
|
|
55
55
|
def initialize(**options)
|
56
56
|
@symbol = options[:symbol] || '$'
|
57
57
|
@separator = options[:separator] || '.'
|
58
|
-
@delimeter = options[:
|
58
|
+
@delimeter = options[:delimeter] || ','
|
59
59
|
@places = options[:precision] || 2
|
60
60
|
@zero = options[:zero] || '0'
|
61
61
|
|
@@ -69,9 +69,9 @@ module Latinum
|
|
69
69
|
# Formats the amount using the configured symbol, separator, delimeter, and places.
|
70
70
|
# e.g. "$5,000.00 NZD". Rounds the amount to the specified number of decimal places.
|
71
71
|
# @returns [String] The formatted string.
|
72
|
-
def format(amount, **options)
|
72
|
+
def format(amount, places: @places, **options)
|
73
73
|
# Round to the desired number of places. Truncation used to be the default.
|
74
|
-
amount = amount.round(
|
74
|
+
amount = amount.round(places).to_d
|
75
75
|
|
76
76
|
integral, fraction = amount.abs.to_s('F').split(/\./, 2)
|
77
77
|
|
@@ -79,7 +79,7 @@ module Latinum
|
|
79
79
|
sign = '-' if amount < 0
|
80
80
|
|
81
81
|
# Decimal places, e.g. the '.00' in '$10.00'
|
82
|
-
fraction = fraction[0
|
82
|
+
fraction = fraction[0...places].ljust(places, @zero)
|
83
83
|
|
84
84
|
# Grouping, e.g. the ',' in '$10,000.00'
|
85
85
|
remainder = integral.size % 3
|
@@ -92,7 +92,7 @@ module Latinum
|
|
92
92
|
name = options.fetch(:name, @name)
|
93
93
|
suffix = name ? " #{name}" : ''
|
94
94
|
|
95
|
-
if
|
95
|
+
if places > 0
|
96
96
|
"#{value}#{@separator}#{fraction}#{suffix}"
|
97
97
|
else
|
98
98
|
"#{value}#{suffix}"
|
data/lib/latinum/resource.rb
CHANGED
@@ -49,7 +49,7 @@ module Latinum
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
# Dump a string
|
52
|
+
# Dump a string representation of a resource.
|
53
53
|
# @parameter resource [Resource] The resource to dump.
|
54
54
|
# @returns [String | Nil] A string that represents the {Resource}.
|
55
55
|
def self.dump(resource)
|
data/lib/latinum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: latinum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|