si_senior 0.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTIzYTRiMWI1M2M3YzE5NDE1Y2E4ZDkyNWRhNjM1NGMyYzg5OTE2Mw==
5
+ data.tar.gz: !binary |-
6
+ OWU1ZjZiNjczMzE5YWE3NDI4MGFhZmYxNWNiNzk4YTNhZDA1NmFkZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ODcyZmRiYzUzZmYwMzFiMDkxNmZkZmRkYzBjYTdhY2MxYzIxOWFkODdiY2Ux
10
+ ODhiOGRlZTVhNGUwNTE0ZmY5NTQwYTZkOWMyY2I3OTM2OGNmYmRmMDdmZmNm
11
+ ZWFjOTk2Y2RjNWUwNDg4ZTBlN2JjN2I2OWUyZjY5ODZhMzYzMTU=
12
+ data.tar.gz: !binary |-
13
+ YmQ2YWU3OTQ5YzMzYWYyMTgyYTFjNzBiZDZiZjJkZmNhNzcxZjMwNGVlZGM2
14
+ ZGI1NTY0ODZmNTAzOWIxNzBmNjRkNjgzNTQwODE2MTFkOTVlZGNhYzk4YmUy
15
+ NjEwYWVmZDYyMDU1ZWVkNTdhMzBjOGEyYzI4MjQzZmFiOGQ4NWQ=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in si_senior.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Tomasz Wójcik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tomasz Wojcik
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ SI señor
2
+ =========
3
+
4
+ SI señor is a simple SI prefix converter.<br>
5
+ Assume that you always have basic SI unit for conversion (seconds for time, meters for length and so on).
6
+
7
+ #### Sample usage
8
+ `1.milli`<br>
9
+ `1.kilo.to_mega`<br>
10
+ `1.to_centi`<br>
11
+
12
+ #### Wiki for SI & SI prefixes
13
+ http://en.wikipedia.org/wiki/SI<br>
14
+ http://en.wikipedia.org/wiki/SI_prefix<br>
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ module SiSenior
2
+ module Constant
3
+ require 'bigdecimal'
4
+
5
+ YOTTA = BigDecimal.new('1.0e+24')
6
+ ZETTA = BigDecimal.new('1.0e+21')
7
+ EXA = BigDecimal.new('1.0e+18')
8
+ PETA = BigDecimal.new('1.0e+15')
9
+ TERA = BigDecimal.new('1.0e+12')
10
+ GIGA = BigDecimal.new('1.0e+9')
11
+ MEGA = BigDecimal.new('1.0e+6')
12
+ KILO = BigDecimal.new('1.0e+3')
13
+ HECTO = BigDecimal.new('1.0e+2')
14
+ DECA = BigDecimal.new('1.0e+1')
15
+
16
+ DECI = BigDecimal.new('1.0e-1')
17
+ CENTI = BigDecimal.new('1.0e-2')
18
+ MILLI = BigDecimal.new('1.0e-3')
19
+ MICRO = BigDecimal.new('1.0e-6')
20
+ NANO = BigDecimal.new('1.0e-9')
21
+ PICO = BigDecimal.new('1.0e-12')
22
+ FEMTO = BigDecimal.new('1.0e-15')
23
+ ATTO = BigDecimal.new('1.0e-18')
24
+ ZEPTO = BigDecimal.new('1.0e-21')
25
+ YOCTO = BigDecimal.new('1.0e-24')
26
+ end
27
+ end
@@ -0,0 +1,176 @@
1
+ require 'si_senior/constant'
2
+
3
+ module SiSenior
4
+ module CoreExt
5
+ require 'bigdecimal'
6
+ include SiSenior::Constant
7
+
8
+ # Prefixes
9
+ def yotta
10
+ big_self * YOTTA
11
+ end
12
+
13
+ def zetta
14
+ big_self * ZETTA
15
+ end
16
+
17
+ def exa
18
+ big_self * EXA
19
+ end
20
+
21
+ def peta
22
+ big_self * PETA
23
+ end
24
+
25
+ def tera
26
+ big_self * TERA
27
+ end
28
+
29
+ def giga
30
+ big_self * GIGA
31
+ end
32
+
33
+ def mega
34
+ big_self * MEGA
35
+ end
36
+
37
+ def kilo
38
+ big_self * KILO
39
+ end
40
+
41
+ def hecto
42
+ big_self * HECTO
43
+ end
44
+
45
+ def deca
46
+ big_self * DECA
47
+ end
48
+
49
+ def deci
50
+ big_self * DECI
51
+ end
52
+
53
+ def centi
54
+ big_self * CENTI
55
+ end
56
+
57
+ def milli
58
+ big_self * MILLI
59
+ end
60
+
61
+ def micro
62
+ big_self * MICRO
63
+ end
64
+
65
+ def nano
66
+ big_self * NANO
67
+ end
68
+
69
+ def pico
70
+ big_self * PICO
71
+ end
72
+
73
+ def femto
74
+ big_self * FEMTO
75
+ end
76
+
77
+ def atto
78
+ big_self * ATTO
79
+ end
80
+
81
+ def zepto
82
+ big_self * ZEPTO
83
+ end
84
+
85
+ def yocto
86
+ big_self * YOCTO
87
+ end
88
+
89
+ # Converters
90
+
91
+ def to_yotta
92
+ big_self / YOTTA
93
+ end
94
+
95
+ def to_zetta
96
+ big_self / ZETTA
97
+ end
98
+
99
+ def to_exa
100
+ big_self / EXA
101
+ end
102
+
103
+ def to_peta
104
+ big_self / PETA
105
+ end
106
+
107
+ def to_tera
108
+ big_self / TERA
109
+ end
110
+
111
+ def to_giga
112
+ big_self / GIGA
113
+ end
114
+
115
+ def to_mega
116
+ big_self / MEGA
117
+ end
118
+
119
+ def to_kilo
120
+ big_self / KILO
121
+ end
122
+
123
+ def to_hecto
124
+ big_self / HECTO
125
+ end
126
+
127
+ def to_deca
128
+ big_self / DECA
129
+ end
130
+
131
+ def to_deci
132
+ big_self / DECI
133
+ end
134
+
135
+ def to_centi
136
+ big_self / CENTI
137
+ end
138
+
139
+ def to_milli
140
+ big_self / MILLI
141
+ end
142
+
143
+ def to_micro
144
+ big_self / MICRO
145
+ end
146
+
147
+ def to_nano
148
+ big_self / NANO
149
+ end
150
+
151
+ def to_pico
152
+ big_self / PICO
153
+ end
154
+
155
+ def to_femto
156
+ big_self / FEMTO
157
+ end
158
+
159
+ def to_atto
160
+ big_self / ATTO
161
+ end
162
+
163
+ def to_zepto
164
+ big_self / ZEPTO
165
+ end
166
+
167
+ def to_yocto
168
+ big_self / YOCTO
169
+ end
170
+
171
+ private
172
+ def big_self
173
+ BigDecimal.new(self)
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,3 @@
1
+ module SiSenior
2
+ VERSION = "0.0.1"
3
+ end
data/lib/si_senior.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "si_senior/version"
2
+ require "si_senior/core_ext"
3
+
4
+ module SiSenior
5
+ # Your code goes here...
6
+ end
7
+
8
+ Numeric.send :include, SiSenior::CoreExt
data/si_senior.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'si_senior/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "si_senior"
8
+ spec.version = SiSenior::VERSION
9
+ spec.authors = ["Tomasz Wojcik"]
10
+ spec.email = ["wojcik.tomek@gmail.com"]
11
+ spec.description = "SI unit converter."
12
+ spec.summary = "SI unit converter."
13
+ spec.homepage = "https://github.com/tomaszwojcik/si_senior"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rspec", "~> 2.14"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,101 @@
1
+ require 'si_senior'
2
+
3
+ describe SiSenior do
4
+
5
+ it 'returns 1.0e+24 for 1.yotta' do
6
+ expect(1.yotta).to eq 1.0e+24
7
+ end
8
+
9
+ it 'returns 1.0e+21 for 1.zetta'do
10
+ expect(1.zetta).to eq 1.0e+21
11
+ end
12
+
13
+ it 'returns 1.0e+18 for 1.exa' do
14
+ expect(1.exa).to eq 1.0e+18
15
+ end
16
+
17
+ it 'returns 1.0e+15 for 1.peta' do
18
+ expect(1.peta).to eq 1.0e+15
19
+ end
20
+
21
+ it 'retruns 1.0e+12 for 1.tera' do
22
+ expect(1.tera).to eq 1.0e+12
23
+ end
24
+
25
+ it 'returns 1.0e+9 for 1.giga' do
26
+ expect(1.giga).to eq 1.0e+9
27
+ end
28
+
29
+ it 'returns 1.0e+6 for 1.mega' do
30
+ expect(1.mega).to eq 1.0e+6
31
+ end
32
+
33
+ it 'returns 1.0e+3 for 1.kilo' do
34
+ expect(1.kilo).to eq 1.0e+3
35
+ end
36
+
37
+ it 'returns 1.0e+2 for 1.hecto' do
38
+ expect(1.hecto).to eq 1.0e+2
39
+ end
40
+
41
+ it 'returns 1.0e+1 for 1.deca' do
42
+ expect(1.deca).to eq 1.0e+1
43
+ end
44
+
45
+ it 'returns 1.0e-1 for 1.deci' do
46
+ expect(1.deci).to eq 1.0e-1
47
+ end
48
+
49
+ it 'returns 1.0e-2 for 1.centi' do
50
+ expect(1.centi).to eq 1.0e-2
51
+ end
52
+
53
+ it 'returns 1.0e-3 for 1.milli' do
54
+ expect(1.milli).to eq 1.0e-3
55
+ end
56
+
57
+ it 'returns 1.0e-6 for 1.micro' do
58
+ expect(1.micro).to eq 1.0e-6
59
+ end
60
+
61
+ it 'returns 1.0e-9 for 1.nano' do
62
+ expect(1.nano).to eq 1.0e-9
63
+ end
64
+
65
+ it 'returns 1.0e-12 for 1.pico' do
66
+ expect(1.pico).to eq 1.0e-12
67
+ end
68
+
69
+ it 'returns 1.0e-15 for 1.femto' do
70
+ expect(1.femto).to eq 1.0e-15
71
+ end
72
+
73
+ it 'returns 1.0e-18 for 1.atto' do
74
+ expect(1.atto).to eq 1.0e-18
75
+ end
76
+
77
+ # Investigate BigDecimal requirement here
78
+ # Probably this is the float issue with big floats like 1.0e-21 and 1.0e-24
79
+
80
+ it 'returns 1.0e-21 for 1.zepto' do
81
+ expect(1.zepto).to eq BigDecimal.new('1.0e-21')
82
+ end
83
+
84
+ it 'returns 1.0e-24 for 1.yocto' do
85
+ expect(1.yocto).to eq BigDecimal.new('1.0e-24')
86
+ end
87
+
88
+ it 'converts 1 yotta to 1 yocto' do
89
+ expect(1.yotta.to_yocto).to eq 1.0e+48
90
+ end
91
+
92
+ it 'converts 1 yocto to 1 yotta' do
93
+ expect(1.yocto.to_yotta).to eq 1.0e-48
94
+ end
95
+
96
+ it 'converting from and to thesame prefix returns 1' do
97
+ expect(1.yotta.to_yotta).to eq 1
98
+ expect(1.yocto.to_yocto).to eq 1
99
+ end
100
+
101
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: si_senior
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Wojcik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: SI unit converter.
56
+ email:
57
+ - wojcik.tomek@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/si_senior.rb
69
+ - lib/si_senior/constant.rb
70
+ - lib/si_senior/core_ext.rb
71
+ - lib/si_senior/version.rb
72
+ - si_senior.gemspec
73
+ - spec/lib/si_senior_spec.rb
74
+ homepage: https://github.com/tomaszwojcik/si_senior
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.7
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: SI unit converter.
98
+ test_files:
99
+ - spec/lib/si_senior_spec.rb
100
+ has_rdoc: