sixarm_ruby_numeric_percent 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.
@@ -0,0 +1,3 @@
1
+ �=�R?zP�i�
2
+ 3_�s/���A�;j2C_��2_�[�.��"PRэ�2�9D=)��#�/@񂽦xTQ}`2H$�x���]b<�{.��_��
3
+ ��{��������X�<vӱ�cE��_� ˌi�:���
File without changes
@@ -0,0 +1,6 @@
1
+ CHANGELOG
2
+
3
+ 2012-01-30 1.0.3 Add Infinite special case
4
+ 2012-01-28 1.0.2 Improve Not-a-Number to use respond_to?('nan?')
5
+ 2012-01-20 1.0.1 Add Not-a-Number special case
6
+ 2012-01-15 1.0.0 Publish
@@ -0,0 +1,32 @@
1
+
2
+ = SixArm.com Ruby Gem Install
3
+
4
+
5
+ First-time users: add our gem certificate and source.
6
+ When you do this once, it works for all our gems.
7
+
8
+ sudo wget http://sixarm.com/sixarm.pem
9
+ sudo gem cert --add sixarm.pem
10
+ sudo gem sources --add http://sixarm.com
11
+
12
+ Install the gem with advanced options.
13
+
14
+ sudo gem install sixarm_ruby_numeric_percent --test --trust-policy HighSecurity
15
+
16
+
17
+ == Notes
18
+
19
+ Do you have any questions, comments, suggestions, or feedback?
20
+ Let us know, we're happy to help. Our email is sixarm@sixarm.com
21
+
22
+ Do you want to create your own high security gems?
23
+ Learn how at http://www.rubygems.org/read/chapter/21
24
+
25
+ To see your current gem certificate list:
26
+
27
+ sudo gem cert --list
28
+
29
+ Our cert looks like this:
30
+
31
+ /C=US/ST=California/L=San Francisco/O=SixArm/CN=sixarm.com
32
+
@@ -0,0 +1,25 @@
1
+ LICENSE
2
+
3
+ You may choose any of these open source licenses:
4
+
5
+ - Apache License
6
+ - BSD License
7
+ - CreativeCommons License, Non-commercial Share Alike
8
+ - GNU General Public License Version 2 (GPL 2)
9
+ - GNU Lesser General Public License (LGPL)
10
+ - MIT License
11
+ - Perl Artistic License
12
+ - Ruby License
13
+
14
+ The software is provided "as is", without warranty of any kind,
15
+ express or implied, including but not limited to the warranties of
16
+ merchantability, fitness for a particular purpose and noninfringement.
17
+
18
+ In no event shall the authors or copyright holders be liable for any
19
+ claim, damages or other liability, whether in an action of contract,
20
+ tort or otherwise, arising from, out of or in connection with the
21
+ software or the use or other dealings in the software.
22
+
23
+ This license is for the included software that is created by SixArm;
24
+ some of the included software may have its own licenses, copyrights,
25
+ authors, etc. and these do take precedence over the SixArm license.
@@ -0,0 +1,21 @@
1
+ = SixArm.com » Ruby » Numeric#percent to calculate a percentage
2
+
3
+ Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
4
+ Copyright:: Copyright (c) 2006-2012 Joel Parker Henderson
5
+ License:: See LICENSE.txt file
6
+
7
+ Calculate a number as percentage with rounding:
8
+
9
+ x=0.1234
10
+ x.percent => 12
11
+
12
+ Optional precision:
13
+
14
+ x.percent(nil) => 12 (default is to round to the closest integer)
15
+ x.percent(1) => 10
16
+ x.percent(2) => 12
17
+ x.percent(3) => 12.3
18
+ x.percent(3) => 12.34
19
+
20
+ Note that precision 1 and 2 are optimized for speed and to return integers;
21
+ other precisions return floats.
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.3
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README.rdoc
4
+ =end
5
+
6
+ class Numeric
7
+
8
+
9
+ # Calculate a number as percentage with rounding:
10
+ #
11
+ # x=0.1234
12
+ # x.percent => 12
13
+ #
14
+ # Optional precision:
15
+ #
16
+ # x.percent(nil) => 12 (default is to round to an integer)
17
+ # x.percent(1) => 10
18
+ # x.percent(2) => 12
19
+ # x.percent(3) => 12.3
20
+ # x.percent(4) => 12.34
21
+ #
22
+ # Special cases:
23
+ #
24
+ # NaN.percent => NaN
25
+ # Infinite.percent => Infinite
26
+ #
27
+ # Note that precision 1 and 2 are optimized for speed and also to return integers;
28
+ # other precisions return floats.
29
+
30
+ def percent(precision=nil)
31
+ return self if (respond_to?('nan?') && nan?) || (respond_to?('infinite?') && infinite?)
32
+ # Optimized for speed for the most common cases
33
+ return case precision
34
+ when nil, 2
35
+ (self * 100).round
36
+ when 1
37
+ (self * 10).round * 10
38
+ else
39
+ (self * (10 ** precision)).round.to_f / (10 ** (precision - 2)).to_f
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test/unit'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'sixarm_ruby_numeric_percent'
6
+
7
+ class NumericPercentTest < Test::Unit::TestCase
8
+
9
+ N = 0.12345
10
+ NAN = 0/0.0
11
+ INFINITE = 1/0.0
12
+
13
+ def test_percent_with_precision_nil
14
+ assert_equal(12, N.percent)
15
+ end
16
+
17
+ def test_percent_with_precision_1
18
+ assert_equal(10, N.percent(1))
19
+ end
20
+
21
+ def test_percent_with_precision_2
22
+ assert_equal(12, N.percent(2))
23
+ end
24
+
25
+ def test_percent_with_precision_3_with_round_down
26
+ assert_equal(12.3, N.percent(3))
27
+ end
28
+
29
+ def test_percent_with_precision_4_with_round_up
30
+ assert_equal(12.35, N.percent(4))
31
+ end
32
+
33
+ def test_nan
34
+ assert(NAN.percent.nan?)
35
+ end
36
+
37
+ def test_infinite
38
+ assert(INFINITE.percent.infinite?)
39
+ end
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_numeric_percent
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - SixArm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUd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XhFekFSQmdOVgpCQWdUQ2tOaGJHbG1iM0p1YVdFeEZq
30
+ QVVCZ05WQkFjVERWTmhiaUJHY21GdVkybHpZMjh4RHpBTkJnTlZCQW9UCkJs
31
+ TnBlRUZ5YlRFVE1CRUdBMVVFQXhNS2MybDRZWEp0TG1OdmJZSUpBS1B3RUVU
32
+ VTViSG9NQXdHQTFVZEV3UUYKTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVGQlFB
33
+ RGdZRUFvb0VleFAvb1BhbTFUUDcxU3l1aHhNYit1VHJaYlNRZQpqVkIrRXhS
34
+ d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
35
+ L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
36
+ dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
37
+ Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
38
+ date: 2012-01-31 00:00:00.000000000 Z
39
+ dependencies: []
40
+ description:
41
+ email: sixarm@sixarm.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gemtest
47
+ - CHANGELOG.txt
48
+ - INSTALL.txt
49
+ - LICENSE.txt
50
+ - Rakefile
51
+ - README.rdoc
52
+ - VERSION
53
+ - lib/sixarm_ruby_numeric_percent.rb
54
+ - test/sixarm_ruby_numeric_percent_test.rb
55
+ homepage: http://sixarm.com/
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.15
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: SixArm.com » Ruby » Numeric#percent to calculate a percentage
79
+ test_files:
80
+ - test/sixarm_ruby_numeric_percent_test.rb
81
+ has_rdoc: true
@@ -0,0 +1 @@
1
+ �_����T�\�U8�h]��Ep���Dj��o�=�[U���F.l �ڈ�2,&�^'��|DF�&9/tT�7F��C��4� Y̡�� ����.m1T�(Ad��qb���/�Ï� �$mXG���ET.�