simplificator-conversions 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- metadata +1 -2
- data/lib/conversions.rb +0 -46
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplificator-conversions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- simplificator
|
@@ -38,7 +38,6 @@ files:
|
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
|
-
- lib/conversions.rb
|
42
41
|
- test/conversions_test.rb
|
43
42
|
- test/test_helper.rb
|
44
43
|
has_rdoc: true
|
data/lib/conversions.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module UnitConversions
|
2
|
-
UNITS = ['kg', 'g', 't', 'mm2', 'm2']
|
3
|
-
CONVERT_TO_PATTERN = /(#{UNITS.join('|')})_to_(#{UNITS.join('|')})/
|
4
|
-
CONVERSIONS = {
|
5
|
-
'kg' => {
|
6
|
-
't' => lambda() {|kg| kg / 1000.0 },
|
7
|
-
'g' => lambda() {|kg| kg * 1000 },
|
8
|
-
},
|
9
|
-
'g' => {
|
10
|
-
'kg' => lambda() {|g| g / 1000.0},
|
11
|
-
't' => lambda() {|g| g / (1000.0 * 1000) },
|
12
|
-
},
|
13
|
-
't' => {
|
14
|
-
'kg' => lambda() {|t| t * 1000},
|
15
|
-
'g' => lambda() {|t| t * (1000 * 1000)},
|
16
|
-
},
|
17
|
-
'm2' => {
|
18
|
-
'mm2' => lambda() {|m2| m2 * (1000 * 1000.0)},
|
19
|
-
},
|
20
|
-
'mm2' => {
|
21
|
-
'm2' => lambda() {|mm2| mm2 / (1000 * 1000.0)},
|
22
|
-
},
|
23
|
-
}
|
24
|
-
|
25
|
-
|
26
|
-
def method_missing_with_unit_conversions(m, *args)
|
27
|
-
if args.length == 0
|
28
|
-
m.to_s =~ CONVERT_TO_PATTERN
|
29
|
-
return CONVERSIONS[$1][$2].call(self) if CONVERSIONS[$1] && CONVERSIONS[$1][$2]
|
30
|
-
end
|
31
|
-
method_missing_without_unit_conversions(m, args)
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
class Fixnum
|
37
|
-
include UnitConversions
|
38
|
-
alias :method_missing_without_unit_conversions :method_missing
|
39
|
-
alias :method_missing :method_missing_with_unit_conversions
|
40
|
-
end
|
41
|
-
|
42
|
-
class Float
|
43
|
-
include UnitConversions
|
44
|
-
alias :method_missing_without_unit_conversions :method_missing
|
45
|
-
alias :method_missing :method_missing_with_unit_conversions
|
46
|
-
end
|