si_senior 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +4 -0
- data/lib/si_senior/core_ext.rb +40 -3
- data/lib/si_senior/version.rb +1 -1
- data/si_senior.gemspec +1 -1
- data/spec/lib/si_senior_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OThhNWEwYjRkYTVlMDY2NzNmZGUwMmFmNDQyOWExZjA3MDZjOWFkOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDFhMGEzZmYxZmZhOTkxYjM0ZWFhN2I1MjNiNTU3YWY3YTZkOTM0Ng==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGU5MzExMTJhZTUyYWZlOGZkMWI5MDAxMGM4N2ZiZjhmYjlhYzk2OTI4Njg4
|
10
|
+
YTJhNjQyOTExOGJmMTAwMDQ0OTlmZTEwNGY0ZWNlYTgwNzViYjc1YTg2Y2U2
|
11
|
+
ZWVlMDJiNzhhN2Y4N2NmMzJjYjA2MjJhNzBjZmIwYTkxYmZjNjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTg3NDQzNWM1MGQwYzY4NDdiOTIxNWM0YmYwOTgyY2RmYjIwNDkzNmEyZjQ4
|
14
|
+
Y2Y5ZGNmMWQ1NWM1NmM5YTBjZDY0MGI1MzI1ODg0Njk2MWE0MTFkMjUyMGUz
|
15
|
+
N2RkZjA2YTFiYTIyMGUwZmE5YWQ3YjdkOGE4YWEzZDYxOTkxNjY=
|
data/README.md
CHANGED
@@ -4,6 +4,10 @@ SI señor
|
|
4
4
|
SI señor is a simple SI prefix converter.<br>
|
5
5
|
Assume that you always have basic SI unit for conversion (seconds for time, meters for length and so on).
|
6
6
|
|
7
|
+
##### Important
|
8
|
+
All operations are done on BigDecimal (numbers are automatically converted) - you have to use
|
9
|
+
[`BigDecimal#to_s(s)`](http://www.ruby-doc.org/stdlib-2.0/libdoc/bigdecimal/rdoc/BigDecimal.html#method-i-to_s) after prefixing or converting to get pretty formatting.
|
10
|
+
|
7
11
|
#### Sample usage
|
8
12
|
`1.milli`<br>
|
9
13
|
`1.kilo.to_mega`<br>
|
data/lib/si_senior/core_ext.rb
CHANGED
@@ -5,165 +5,202 @@ module SiSenior
|
|
5
5
|
require 'bigdecimal'
|
6
6
|
include SiSenior::Constant
|
7
7
|
|
8
|
-
#
|
8
|
+
# Returns BigDecimal result of prefixing with yotta (multiplies value by 1.0e+24)
|
9
9
|
def yotta
|
10
10
|
big_self * YOTTA
|
11
11
|
end
|
12
12
|
|
13
|
+
# Returns BigDecimal result of prefixing with zetta (multiplies value by 1.0e+21)
|
13
14
|
def zetta
|
14
15
|
big_self * ZETTA
|
15
16
|
end
|
16
17
|
|
18
|
+
# Returns BigDecimal result of prefixing with exa (multiplies value by 1.0e+18)
|
17
19
|
def exa
|
18
20
|
big_self * EXA
|
19
21
|
end
|
20
22
|
|
23
|
+
# Returns BigDecimal result of prefixing with peta (multiplies value by 1.0e+15)
|
21
24
|
def peta
|
22
25
|
big_self * PETA
|
23
26
|
end
|
24
27
|
|
28
|
+
# Returns BigDecimal result of prefixing with tera (multiplies value by 1.0e+12)
|
25
29
|
def tera
|
26
30
|
big_self * TERA
|
27
31
|
end
|
28
32
|
|
33
|
+
# Returns BigDecimal result of prefixing with giga (multiplies value by 1.0e+9)
|
29
34
|
def giga
|
30
35
|
big_self * GIGA
|
31
36
|
end
|
32
37
|
|
38
|
+
# Returns BigDecimal result of prefixing with mega (multiplies value by 1.0e+6)
|
33
39
|
def mega
|
34
40
|
big_self * MEGA
|
35
41
|
end
|
36
42
|
|
43
|
+
# Returns BigDecimal result of prefixing with kilo (multiplies value by 1.0e+3)
|
37
44
|
def kilo
|
38
45
|
big_self * KILO
|
39
46
|
end
|
40
47
|
|
48
|
+
# Returns BigDecimal result of prefixing with hecto (multiplies value by 1.0e+2)
|
41
49
|
def hecto
|
42
50
|
big_self * HECTO
|
43
51
|
end
|
44
52
|
|
53
|
+
# Returns BigDecimal result of prefixing with deca (multiplies value by 1.0e+1)
|
45
54
|
def deca
|
46
55
|
big_self * DECA
|
47
56
|
end
|
48
57
|
|
58
|
+
# Returns BigDecimal result of prefixing with deci (multiples value by 1.0e-1)
|
49
59
|
def deci
|
50
60
|
big_self * DECI
|
51
61
|
end
|
52
62
|
|
63
|
+
# Returns BigDecimal result of prefixing with centi (multiples value by 1.0e-2)
|
53
64
|
def centi
|
54
65
|
big_self * CENTI
|
55
66
|
end
|
56
67
|
|
68
|
+
# Returns BigDecimal result of prefixing with milli (multiples value by 1.0e-3)
|
57
69
|
def milli
|
58
70
|
big_self * MILLI
|
59
71
|
end
|
60
72
|
|
73
|
+
# Returns BigDecimal result of prefixing with micro (multiples value by 1.0e-6)
|
61
74
|
def micro
|
62
75
|
big_self * MICRO
|
63
76
|
end
|
64
77
|
|
78
|
+
# Returns BigDecimal result of prefixing with nano (multiples value by 1.0e-9)
|
65
79
|
def nano
|
66
80
|
big_self * NANO
|
67
81
|
end
|
68
82
|
|
83
|
+
# Returns BigDecimal result of prefixing with pico (multiples value by 1.0e-12)
|
69
84
|
def pico
|
70
85
|
big_self * PICO
|
71
86
|
end
|
72
87
|
|
88
|
+
# Returns BigDecimal result of prefixing with femto (multiples value by 1.0e-15)
|
73
89
|
def femto
|
74
90
|
big_self * FEMTO
|
75
91
|
end
|
76
92
|
|
93
|
+
# Returns BigDecimal result of prefixing with atto (multiples value by 1.0e-18)
|
77
94
|
def atto
|
78
95
|
big_self * ATTO
|
79
96
|
end
|
80
97
|
|
98
|
+
# Returns BigDecimal result of prefixing with zepto (multiples value by 1.0e-21)
|
81
99
|
def zepto
|
82
100
|
big_self * ZEPTO
|
83
101
|
end
|
84
102
|
|
103
|
+
# Returns BigDecimal result of prefixing with yocto (multiples value by 1.0e-24)
|
85
104
|
def yocto
|
86
105
|
big_self * YOCTO
|
87
106
|
end
|
88
107
|
|
89
|
-
#
|
90
|
-
|
108
|
+
# Returns BigDecimal result of conversion to yotta (divides by 1.0e+24)
|
91
109
|
def to_yotta
|
92
110
|
big_self / YOTTA
|
93
111
|
end
|
94
112
|
|
113
|
+
# Returns BigDecimal result of conversion to zetta (divides by 1.0e+21)
|
95
114
|
def to_zetta
|
96
115
|
big_self / ZETTA
|
97
116
|
end
|
98
117
|
|
118
|
+
# Returns BigDecimal result of conversion to exa (divides by 1.0e+18)
|
99
119
|
def to_exa
|
100
120
|
big_self / EXA
|
101
121
|
end
|
102
122
|
|
123
|
+
# Returns BigDecimal result of conversion to peta (divides by 1.0e+15)
|
103
124
|
def to_peta
|
104
125
|
big_self / PETA
|
105
126
|
end
|
106
127
|
|
128
|
+
# Returns BigDecimal result of conversion to tera (divides by 1.0e+12)
|
107
129
|
def to_tera
|
108
130
|
big_self / TERA
|
109
131
|
end
|
110
132
|
|
133
|
+
# Returns BigDecimal result of conversion to giga (divides by 1.0e+9)
|
111
134
|
def to_giga
|
112
135
|
big_self / GIGA
|
113
136
|
end
|
114
137
|
|
138
|
+
# Returns BigDecimal result of conversion to mega (divides by 1.0e+6)
|
115
139
|
def to_mega
|
116
140
|
big_self / MEGA
|
117
141
|
end
|
118
142
|
|
143
|
+
# Returns BigDecimal result of conversion to kilo (divides by 1.0e+3)
|
119
144
|
def to_kilo
|
120
145
|
big_self / KILO
|
121
146
|
end
|
122
147
|
|
148
|
+
# Returns BigDecimal result of conversion to hecto (divides by 1.0e+2)
|
123
149
|
def to_hecto
|
124
150
|
big_self / HECTO
|
125
151
|
end
|
126
152
|
|
153
|
+
# Returns BigDecimal result of conversion to deca (divides by 1.0e+1)
|
127
154
|
def to_deca
|
128
155
|
big_self / DECA
|
129
156
|
end
|
130
157
|
|
158
|
+
# Returns BigDecimal result of conversion to deci (divides by 1.0e-1)
|
131
159
|
def to_deci
|
132
160
|
big_self / DECI
|
133
161
|
end
|
134
162
|
|
163
|
+
# Returns BigDecimal result of conversion to centi (divides by 1.0e-2)
|
135
164
|
def to_centi
|
136
165
|
big_self / CENTI
|
137
166
|
end
|
138
167
|
|
168
|
+
# Returns BigDecimal result of conversion to milli (divides by 1.0e-3)
|
139
169
|
def to_milli
|
140
170
|
big_self / MILLI
|
141
171
|
end
|
142
172
|
|
173
|
+
# Returns BigDecimal result of conversion to micro (divides by 1.0e-6)
|
143
174
|
def to_micro
|
144
175
|
big_self / MICRO
|
145
176
|
end
|
146
177
|
|
178
|
+
# Returns BigDecimal result of conversion to nano (divides by 1.0e-9)
|
147
179
|
def to_nano
|
148
180
|
big_self / NANO
|
149
181
|
end
|
150
182
|
|
183
|
+
# Returns BigDecimal result of conversion to pico (divides by 1.0e-12)
|
151
184
|
def to_pico
|
152
185
|
big_self / PICO
|
153
186
|
end
|
154
187
|
|
188
|
+
# Returns BigDecimal result of conversion to femto (divides by 1.0e-15)
|
155
189
|
def to_femto
|
156
190
|
big_self / FEMTO
|
157
191
|
end
|
158
192
|
|
193
|
+
# Returns BigDecimal result of conversion to atto (divides by 1.0e-18)
|
159
194
|
def to_atto
|
160
195
|
big_self / ATTO
|
161
196
|
end
|
162
197
|
|
198
|
+
# Returns BigDecimal result of conversion to zepto (divides by 1.0e-21)
|
163
199
|
def to_zepto
|
164
200
|
big_self / ZEPTO
|
165
201
|
end
|
166
202
|
|
203
|
+
# Returns BigDecimal result of conversion to yocto (divides by 1.0e-24)
|
167
204
|
def to_yocto
|
168
205
|
big_self / YOCTO
|
169
206
|
end
|
data/lib/si_senior/version.rb
CHANGED
data/si_senior.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = SiSenior::VERSION
|
9
9
|
spec.authors = ["Tomasz Wójcik"]
|
10
10
|
spec.email = ["wojcik.tomek@gmail.com"]
|
11
|
-
spec.description = "SI unit converter. Supports prefixes (1.kilo, 5.mega etc) and conversions (1.to_mega, 5.
|
11
|
+
spec.description = "SI unit converter. Supports prefixes (1.kilo, 5.mega etc) and conversions (1.to_mega, 5.milli.to_centi etc)"
|
12
12
|
spec.summary = "SI unit converter."
|
13
13
|
spec.homepage = "https://github.com/tomaszwojcik/si_senior"
|
14
14
|
spec.license = "MIT"
|
data/spec/lib/si_senior_spec.rb
CHANGED
@@ -75,7 +75,7 @@ describe SiSenior do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
# Investigate BigDecimal requirement here
|
78
|
-
# Probably this is
|
78
|
+
# Probably this is the float issue with big floats like 1.0e-21 and 1.0e-24
|
79
79
|
|
80
80
|
it 'returns 1.0e-21 for 1.zepto' do
|
81
81
|
expect(1.zepto).to eq BigDecimal.new('1.0e-21')
|
@@ -93,7 +93,7 @@ describe SiSenior do
|
|
93
93
|
expect(1.yocto.to_yotta).to eq 1.0e-48
|
94
94
|
end
|
95
95
|
|
96
|
-
it 'converting from and to
|
96
|
+
it 'converting from and to the same prefix returns 1' do
|
97
97
|
expect(1.yotta.to_yotta).to eq 1
|
98
98
|
expect(1.yocto.to_yocto).to eq 1
|
99
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: si_senior
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Wójcik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: SI unit converter. Supports prefixes (1.kilo, 5.mega etc) and conversions
|
56
|
-
(1.to_mega, 5.
|
56
|
+
(1.to_mega, 5.milli.to_centi etc)
|
57
57
|
email:
|
58
58
|
- wojcik.tomek@gmail.com
|
59
59
|
executables: []
|