sixarm_ruby_numeric_floor_precision 1.0.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.
data.tar.gz.sig ADDED
Binary file
data/.gemtest ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # SixArm.com » Ruby » <br> Numericfloor_precision to truncate a number to decimal digits
2
+
3
+ * Doc: <http://sixarm.com/sixarm_ruby_numeric_floor_precision/doc>
4
+ * Gem: <http://rubygems.org/gems/sixarm_ruby_numeric_floor_precision>
5
+ * Repo: <http://github.com/sixarm/sixarm_ruby_numeric_floor_precision>
6
+ * Email: Joel Parker Henderson, <joel@sixarm.com>
7
+
8
+
9
+ ## Introduction
10
+
11
+ Calculate a number as percentage with rounding.
12
+
13
+ For docs go to <http://sixarm.com/sixarm_ruby_numeric_floor_precision/doc>
14
+
15
+ Want to help? We're happy to get pull requests.
16
+
17
+
18
+ ## Install quickstart
19
+
20
+ Install:
21
+
22
+ gem install sixarm_ruby_numeric_floor_precision
23
+
24
+ Bundler:
25
+
26
+ gem "sixarm_ruby_numeric_floor_precision", "~>1.0.0"
27
+
28
+ Require:
29
+
30
+ require "sixarm_ruby_numeric_floor_precision"
31
+
32
+
33
+ ## Install with security (optional)
34
+
35
+ To enable high security for all our gems:
36
+
37
+ wget http://sixarm.com/sixarm.pem
38
+ gem cert --add sixarm.pem
39
+ gem sources --add http://sixarm.com
40
+
41
+ To install with high security:
42
+
43
+ gem install sixarm_ruby_numeric_floor_precision --test --trust-policy HighSecurity
44
+
45
+
46
+ ## Examples
47
+
48
+ Truncate a number:
49
+
50
+ require "sixarm_ruby_numeric_floor_precision"
51
+ x=0.1234
52
+ x.floor_precision(2) => 0.12
53
+
54
+
55
+ ## Changes
56
+
57
+ * 2012-09-01 1.0.1 Publish; extracted from existing app.
58
+
59
+
60
+ ## License
61
+
62
+ You may choose any of these open source licenses:
63
+
64
+ * Apache License
65
+ * BSD License
66
+ * CreativeCommons License, Non-commercial Share Alike
67
+ * GNU General Public License Version 2 (GPL 2)
68
+ * GNU Lesser General Public License (LGPL)
69
+ * MIT License
70
+ * Perl Artistic License
71
+ * Ruby License
72
+
73
+ The software is provided "as is", without warranty of any kind,
74
+ express or implied, including but not limited to the warranties of
75
+ merchantability, fitness for a particular purpose and noninfringement.
76
+
77
+ In no event shall the authors or copyright holders be liable for any
78
+ claim, damages or other liability, whether in an action of contract,
79
+ tort or otherwise, arising from, out of or in connection with the
80
+ software or the use or other dealings in the software.
81
+
82
+ This license is for the included software that is created by SixArm;
83
+ some of the included software may have its own licenses, copyrights,
84
+ authors, etc. and these do take precedence over the SixArm license.
85
+
86
+ Copyright (c) 2005-2013 Joel Parker Henderson
data/Rakefile ADDED
@@ -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.0
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README
4
+ =end
5
+
6
+ class Numeric
7
+
8
+ # @return self, truncated to a given precision i.e. decimal digits
9
+ #
10
+ # @example
11
+ # x = 0.12345
12
+ # x.floor_precision(0) => 0.0
13
+ # x.floor_precision(1) => 0.1
14
+ # x.floor_precision(2) => 0.12
15
+ # x.floor_precision(3) => 0.123
16
+ #
17
+ def floor_precision(precision)
18
+ return self if is_a?(Float) && nan?
19
+ (self * (10 ** precision)).truncate.fdiv(10 ** precision)
20
+ end
21
+
22
+ end
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'sixarm_ruby_numeric_floor_precision'
6
+
7
+ describe Numeric do
8
+
9
+ it "#floor_precision" do
10
+ x = 0.12345
11
+ x.floor_precision(0).must_equal 0.0
12
+ x.floor_precision(1).must_equal 0.1
13
+ x.floor_precision(2).must_equal 0.12
14
+ x.floor_precision(3).must_equal 0.123
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_numeric_floor_precision
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - SixArm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
14
+ Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
15
+ TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZB
16
+ WURWUVFIRXcxVFlXNGdSbkpoYm1OcApjMk52TVE4d0RRWURWUVFLRXdaVGFY
17
+ aEJjbTB4RXpBUkJnTlZCQU1UQ25OcGVHRnliUzVqYjIwd0hoY05NVEF4Ck1q
18
+ RXpNak15TnpFeldoY05NVE13T1RBNE1qTXlOekV6V2pCZ01Rc3dDUVlEVlFR
19
+ R0V3SlZVekVUTUJFR0ExVUUKQ0JNS1EyRnNhV1p2Y201cFlURVdNQlFHQTFV
20
+ RUJ4TU5VMkZ1SUVaeVlXNWphWE5qYnpFUE1BMEdBMVVFQ2hNRwpVMmw0UVhK
21
+ dE1STXdFUVlEVlFRREV3cHphWGhoY20wdVkyOXRNSUdmTUEwR0NTcUdTSWIz
22
+ RFFFQkFRVUFBNEdOCkFEQ0JpUUtCZ1FDOTRtRDlKRHdCc3Vuc09JMFZSM0NY
23
+ WGJPV2c5Y1dhV2Npd0Z5Sk5GaU03QTlJOEtQTGZYVXcKUUM0Y3pVZTVadUc0
24
+ V0h2aW5yV2hrckNLKzFkV0Jxb0VDbHhkRi9Gb0tPNWErdG9uR0Nqam1meTgx
25
+ Sm1Gamp5eAplVHNqc0h5dncrUWlrOWtwZjlhajYrcG5rTnJWc3dnTkhWZWEy
26
+ bzl5YWJiRWlTNlZTZUpXb1FJREFRQUJvNEhGCk1JSENNQjBHQTFVZERnUVdC
27
+ QlF6UEp0cW1TZ2M1M2VETjdhU3pEUXdyOVRBTERDQmtnWURWUjBqQklHS01J
28
+ R0gKZ0JRelBKdHFtU2djNTNlRE43YVN6RFF3cjlUQUxLRmtwR0l3WURFTE1B
29
+ a0dBMVVFQmhNQ1ZWTXhFekFSQmdOVgpCQWdUQ2tOaGJHbG1iM0p1YVdFeEZq
30
+ QVVCZ05WQkFjVERWTmhiaUJHY21GdVkybHpZMjh4RHpBTkJnTlZCQW9UCkJs
31
+ TnBlRUZ5YlRFVE1CRUdBMVVFQXhNS2MybDRZWEp0TG1OdmJZSUpBS1B3RUVU
32
+ VTViSG9NQXdHQTFVZEV3UUYKTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVGQlFB
33
+ RGdZRUFvb0VleFAvb1BhbTFUUDcxU3l1aHhNYit1VHJaYlNRZQpqVkIrRXhS
34
+ d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
35
+ L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
36
+ dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
37
+ Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
38
+ date: 2012-09-02 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
+ - Rakefile
48
+ - README.md
49
+ - VERSION
50
+ - lib/sixarm_ruby_numeric_floor_precision.rb
51
+ - test/sixarm_ruby_numeric_floor_precision_test.rb
52
+ homepage: http://sixarm.com/
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.23
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: SixArm.com » Ruby » Numeric#floor_precision to truncate a number to digits
76
+ test_files:
77
+ - test/sixarm_ruby_numeric_floor_precision_test.rb
78
+ has_rdoc: true
metadata.gz.sig ADDED
Binary file