percentage 1.4.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +16 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/percentage.rb +25 -1
- data/percentage.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21374fb1c476c85b4a4380ee15c3366aae81897a381c78eecfe4c439f4f333ab
|
4
|
+
data.tar.gz: f7be43bf545ffa5982a22a3da8ecd2692f114335a88be8090190b297d178b298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2305a119de4fb3e426a20ca722cb3dcd14c46039d24e5b8c16328e74cbe43514c673fa20c83fb9d8f6d62d909e518e545f6a33be46a3ecc11ab6ffe3408b31f4
|
7
|
+
data.tar.gz: 6ac6258c6234e35a32b747f1317b725e84c3fdee226248b076d55fab34e4b2d43a54333de958eb6750640de3ae815a2a1657cbe279354f615dc3e1832f6ddec2
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# 2.1.0
|
2
|
+
|
3
|
+
* Added Percentage#-@
|
4
|
+
|
5
|
+
* Added Percentage#positive?
|
6
|
+
|
7
|
+
* Added Percentage#negative?
|
8
|
+
|
9
|
+
# 2.0.0
|
10
|
+
|
11
|
+
* Added Percentage#to_d
|
12
|
+
|
13
|
+
* Percentage instances are now frozen on initialization
|
14
|
+
|
15
|
+
* Changed `Percentage.change` to return `nil` when first argument is zero
|
16
|
+
|
1
17
|
# 1.4.1
|
2
18
|
|
3
19
|
* Added CHANGES.md to gem files
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# percentage
|
2
2
|
|
3
3
|
![Gem Version](https://badge.fury.io/rb/percentage.svg)
|
4
|
-
![
|
4
|
+
![Test Status](https://github.com/readysteady/percentage/actions/workflows/test.yml/badge.svg)
|
5
5
|
|
6
6
|
|
7
7
|
Ruby gem for working with percentages.
|
data/lib/percentage.rb
CHANGED
@@ -7,6 +7,8 @@ class Percentage
|
|
7
7
|
|
8
8
|
def initialize(value)
|
9
9
|
@value = value
|
10
|
+
|
11
|
+
freeze
|
10
12
|
end
|
11
13
|
|
12
14
|
def to_i
|
@@ -25,6 +27,16 @@ class Percentage
|
|
25
27
|
fractional_value.to_r
|
26
28
|
end
|
27
29
|
|
30
|
+
def to_d
|
31
|
+
if @value.integer?
|
32
|
+
@value.to_d / 100
|
33
|
+
elsif BigDecimal === @value
|
34
|
+
@value
|
35
|
+
else
|
36
|
+
@value.to_d(0)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
28
40
|
def zero?
|
29
41
|
@value.zero?
|
30
42
|
end
|
@@ -91,6 +103,18 @@ class Percentage
|
|
91
103
|
self.class.new(@value * n)
|
92
104
|
end
|
93
105
|
|
106
|
+
def -@
|
107
|
+
self.class.new(-@value)
|
108
|
+
end
|
109
|
+
|
110
|
+
def positive?
|
111
|
+
@value.positive?
|
112
|
+
end
|
113
|
+
|
114
|
+
def negative?
|
115
|
+
@value.negative?
|
116
|
+
end
|
117
|
+
|
94
118
|
protected
|
95
119
|
|
96
120
|
def fractional_value
|
@@ -115,7 +139,7 @@ def Percentage(object)
|
|
115
139
|
end
|
116
140
|
|
117
141
|
def Percentage.change(a, b)
|
118
|
-
Percentage.new((b - a).to_r / a)
|
142
|
+
Percentage.new((b - a).to_r / a) unless a.zero?
|
119
143
|
end
|
120
144
|
|
121
145
|
class BigDecimal
|
data/percentage.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percentage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.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:
|
11
|
+
date: 2024-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem for working with percentages
|
14
14
|
email:
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
|
-
rubygems_version: 3.
|
49
|
+
rubygems_version: 3.4.10
|
50
50
|
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: See description
|