percentage 2.1.1 → 2.3.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: da6d1c6c5ff20dee1500808d27aa029754cf4ac8771a9750363de4c701c37a15
4
- data.tar.gz: f5021e0a31e03ccdf52108e7ba5e0c743567afbf0ff4716449e60c76d788a0b2
3
+ metadata.gz: d3962a510e791ec11f17b93dc34bb162d7af6129a5f4cd8a37bada8eb9abab85
4
+ data.tar.gz: 7fe5102660e503e2908a2fa67907c8678d947cf64b33dee12c186f0f33d60628
5
5
  SHA512:
6
- metadata.gz: 97fc4161adefd0e64646970976af477a71830534c399a5d9a7d89022a61ba065a57b9698af64cfdc8413aeb6c68cf860aa2d79931811dcf830b21f23b3888e0d
7
- data.tar.gz: a526ad11816cb946dacf2ee16973485e236d2e826d5811113ada545b3a8b73db81607f26cbdd629474dc637525cd35901a71c383c2e62ba0956fefb070bece48
6
+ metadata.gz: a171aa1ac38e246bd24ea9fde11f5c4f5a8fec689b1942b19a7625ffd4b9fa2abf0280cf908a42c66cf7b404ecb6c0275f09b9478d5f82c0cce54e9669d3a4d8
7
+ data.tar.gz: 8c669769c44e568ef1356d939dfda3b7f59137255fbcd8e9221a55a0b9181393bb99204769ea17e771ee07849753b04c94e29e0618d7976f406a93fdc278568c
data/CHANGES.md CHANGED
@@ -1,3 +1,19 @@
1
+ # 2.3.0
2
+
3
+ * **Required ruby version is now 2.5.0**
4
+
5
+ * Added Percentage#nonzero?
6
+
7
+ * Added Percentage#inspect
8
+
9
+ # 2.2.0
10
+
11
+ * Added Rational#to_percentage
12
+
13
+ * Added Rational#percent_of
14
+
15
+ * Added Rational#as_percentage_of
16
+
1
17
  # 2.1.1
2
18
 
3
19
  * Added bigdecimal gem dependency (thanks @orien)
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2024 TIMCRAFT
1
+ Copyright (c) 2012-2025 TIMCRAFT
2
2
 
3
3
  This is an Open Source project licensed under the terms of the LGPLv3 license.
4
4
  Please see <http://www.gnu.org/licenses/lgpl-3.0.html> for license text.
data/lib/percentage.rb CHANGED
@@ -41,6 +41,11 @@ class Percentage
41
41
  @value.zero?
42
42
  end
43
43
 
44
+ def nonzero?
45
+ return if @value.zero?
46
+ self
47
+ end
48
+
44
49
  def <=>(object)
45
50
  if self.class === object
46
51
  fractional_value <=> object.fractional_value
@@ -115,6 +120,10 @@ class Percentage
115
120
  @value.negative?
116
121
  end
117
122
 
123
+ def inspect
124
+ "<Percentage: value=#{value.inspect}>"
125
+ end
126
+
118
127
  protected
119
128
 
120
129
  def fractional_value
@@ -142,6 +151,20 @@ def Percentage.change(a, b)
142
151
  Percentage.new((b - a).to_r / a) unless a.zero?
143
152
  end
144
153
 
154
+ class Rational
155
+ def to_percentage
156
+ Percentage(self)
157
+ end
158
+
159
+ def percent_of(n)
160
+ n * Percentage(self)
161
+ end
162
+
163
+ def as_percentage_of(n)
164
+ Percentage.new(self / n)
165
+ end
166
+ end
167
+
145
168
  class BigDecimal
146
169
  def to_percentage
147
170
  Percentage(self)
data/percentage.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'percentage'
3
- s.version = '2.1.1'
3
+ s.version = '2.3.0'
4
4
  s.license = 'LGPL-3.0'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Tim Craft']
7
- s.email = ['mail@timcraft.com']
7
+ s.email = ['email@timcraft.com']
8
8
  s.homepage = 'https://github.com/readysteady/percentage'
9
9
  s.description = 'Ruby gem for working with percentages'
10
10
  s.summary = 'See description'
11
11
  s.files = Dir.glob('lib/**/*.rb') + %w[CHANGES.md LICENSE.txt README.md percentage.gemspec]
12
- s.required_ruby_version = '>= 1.9.3'
12
+ s.required_ruby_version = '>= 2.5.0'
13
13
  s.require_path = 'lib'
14
14
  s.metadata = {
15
15
  'homepage' => 'https://github.com/readysteady/percentage',
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
17
17
  'bug_tracker_uri' => 'https://github.com/readysteady/percentage/issues',
18
18
  'changelog_uri' => 'https://github.com/readysteady/percentage/blob/main/CHANGES.md'
19
19
  }
20
- s.add_runtime_dependency 'bigdecimal'
20
+ s.add_dependency 'bigdecimal', '~> 3'
21
21
  end
metadata CHANGED
@@ -1,32 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percentage
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-03-06 00:00:00.000000000 Z
10
+ date: 2025-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bigdecimal
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: '3'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">="
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
25
+ version: '3'
27
26
  description: Ruby gem for working with percentages
28
27
  email:
29
- - mail@timcraft.com
28
+ - email@timcraft.com
30
29
  executables: []
31
30
  extensions: []
32
31
  extra_rdoc_files: []
@@ -45,7 +44,6 @@ metadata:
45
44
  source_code_uri: https://github.com/readysteady/percentage
46
45
  bug_tracker_uri: https://github.com/readysteady/percentage/issues
47
46
  changelog_uri: https://github.com/readysteady/percentage/blob/main/CHANGES.md
48
- post_install_message:
49
47
  rdoc_options: []
50
48
  require_paths:
51
49
  - lib
@@ -53,15 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
51
  requirements:
54
52
  - - ">="
55
53
  - !ruby/object:Gem::Version
56
- version: 1.9.3
54
+ version: 2.5.0
57
55
  required_rubygems_version: !ruby/object:Gem::Requirement
58
56
  requirements:
59
57
  - - ">="
60
58
  - !ruby/object:Gem::Version
61
59
  version: '0'
62
60
  requirements: []
63
- rubygems_version: 3.5.3
64
- signing_key:
61
+ rubygems_version: 3.6.2
65
62
  specification_version: 4
66
63
  summary: See description
67
64
  test_files: []