weight_converter 0.0.4 → 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.
- checksums.yaml +4 -4
- data/bin/weight_converter +4 -1
- data/lib/weight_converter.rb +37 -8
- data/spec/weight_converter_spec.rb +36 -0
- data/weight_converter.gemspec +20 -0
- metadata +5 -3
- data/lib/weight_converter/random_class.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a81cd8eb6247f4a1e6abd7b9b21859c79a92e69b88828156319aa2724885aaf
|
4
|
+
data.tar.gz: 7eb6304e681e8efc9544c0f2f4dceba4710e13197bd0291f677584f401fd3244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0423d97b3948898659d332345a8d834445c11e57ee9e26f71b15ed64d5767c147dbbfe2b7052cf4a75dd6a41f41067a046b4cb1805cae2b99d796c73ab12207e
|
7
|
+
data.tar.gz: c6db0bd916111b7b663faf122f0e737df6f4cc9bcb4df583517344ba3ea4b7f98b3c403ed4bb102e65da3614ac5dea332e5b81616b469273f5f6912f3e690dac
|
data/bin/weight_converter
CHANGED
data/lib/weight_converter.rb
CHANGED
@@ -1,11 +1,40 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
1
3
|
class WeightConverter
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
@@weights = {
|
5
|
+
"kg": 1000,
|
6
|
+
"t": 1_000_000,
|
7
|
+
"cent": 100_000,
|
8
|
+
"ct": 0.2,
|
9
|
+
"g": 1,
|
10
|
+
"mg": 0.001,
|
11
|
+
"mkg": 0.000001,
|
12
|
+
"lot": 1_016_000,
|
13
|
+
"sht": 907_180,
|
14
|
+
"kip": 453592,
|
15
|
+
"st": 6350.29,
|
16
|
+
"lb": 453.592,
|
17
|
+
"oz": 28.3495,
|
18
|
+
"dr": 3.4,
|
19
|
+
"gr": 0.065,
|
20
|
+
"lbt": 373.24,
|
21
|
+
"ozt": 31.1,
|
22
|
+
"dwt": 1.55517,
|
23
|
+
}
|
24
|
+
|
25
|
+
def convert(number, from, to, color)
|
26
|
+
return colorize(convert_g_to(convert_to_g(number.to_f, from), to).to_s, color)
|
27
|
+
end
|
28
|
+
|
29
|
+
def convert_to_g(number, from)
|
30
|
+
return number * @@weights[from]
|
8
31
|
end
|
9
|
-
end
|
10
32
|
|
11
|
-
|
33
|
+
def convert_g_to(number, to)
|
34
|
+
return number / @@weights[to]
|
35
|
+
end
|
36
|
+
|
37
|
+
def colorize(string, color)
|
38
|
+
string.colorize(color)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "weight_converter"
|
2
|
+
|
3
|
+
describe WeightConverter do
|
4
|
+
weight_converter = WeightConverter.new
|
5
|
+
describe "#convert_to_g" do
|
6
|
+
context "convert weight in given units to grams" do
|
7
|
+
it "return 100_000" do
|
8
|
+
expect(weight_converter.convert_to_g(100, :kg)). to be_within(0.1).of(100_000)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "return 22_679_600" do
|
12
|
+
expect(weight_converter.convert_to_g(50, :kip)). to be_within(0.1).of(22_679_600)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "return 311" do
|
16
|
+
expect(weight_converter.convert_to_g(10, :ozt)). to be_within(0.1).of(311)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#convert_g_to" do
|
22
|
+
context "convert weight in grams to given units" do
|
23
|
+
it "return 500" do
|
24
|
+
expect(weight_converter.convert_g_to(1000, :ct)). to be_within(0.1).of(5000)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "return 588" do
|
28
|
+
expect(weight_converter.convert_g_to(2000, :dr)). to be_within(0.1).of(588.235294118)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "return 0.0001" do
|
32
|
+
expect(weight_converter.convert_g_to(10, :cent)). to be_within(0.1).of(0.0001)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'weight_converter'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.date = '2010-04-28'
|
5
|
+
s.summary = "weight_converter!"
|
6
|
+
s.executables << 'weight_converter'
|
7
|
+
s.description = "weight_converter"
|
8
|
+
s.authors = ["Mereum"]
|
9
|
+
s.email = 'mereum@quaran.to'
|
10
|
+
s.files = ["lib/weight_converter.rb",
|
11
|
+
"weight_converter.gemspec",
|
12
|
+
"spec/weight_converter_spec.rb"
|
13
|
+
]
|
14
|
+
s.test_files = [
|
15
|
+
'spec/weight_converter_spec.rb'
|
16
|
+
]
|
17
|
+
s.homepage =
|
18
|
+
'https://rubygems.org/gems/hola'
|
19
|
+
s.license = 'MIT'
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weight_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mereum
|
@@ -19,7 +19,8 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- bin/weight_converter
|
21
21
|
- lib/weight_converter.rb
|
22
|
-
-
|
22
|
+
- spec/weight_converter_spec.rb
|
23
|
+
- weight_converter.gemspec
|
23
24
|
homepage: https://rubygems.org/gems/hola
|
24
25
|
licenses:
|
25
26
|
- MIT
|
@@ -43,4 +44,5 @@ rubygems_version: 3.0.3
|
|
43
44
|
signing_key:
|
44
45
|
specification_version: 4
|
45
46
|
summary: weight_converter!
|
46
|
-
test_files:
|
47
|
+
test_files:
|
48
|
+
- spec/weight_converter_spec.rb
|