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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb6ae132e89f37bc5bdd5258484b298e9fba2f966c869b2e631623f0862c25fd
4
- data.tar.gz: e1a5a1652c6c2924fd52ed6788bc7b2cd6346981f47c898d314ee53120e22322
3
+ metadata.gz: 6a81cd8eb6247f4a1e6abd7b9b21859c79a92e69b88828156319aa2724885aaf
4
+ data.tar.gz: 7eb6304e681e8efc9544c0f2f4dceba4710e13197bd0291f677584f401fd3244
5
5
  SHA512:
6
- metadata.gz: df5621304aa3d469050cb0fc706647e96cfd872dd3cc0d1dca6a80e6623c22b33d9d21bb826dc7f7322cd0d06fbcc21ce76d8974b3bebf226a0caa75cd36116c
7
- data.tar.gz: 776517f04ccefa9c10786e8773fb5b4b67fec21edb2b3c253deb35e576623b01e199aee26edf35c09945a1f6d9bf542f3c32f5c1f5a94adec4062edd875b84db
6
+ metadata.gz: 0423d97b3948898659d332345a8d834445c11e57ee9e26f71b15ed64d5767c147dbbfe2b7052cf4a75dd6a41f41067a046b4cb1805cae2b99d796c73ab12207e
7
+ data.tar.gz: c6db0bd916111b7b663faf122f0e737df6f4cc9bcb4df583517344ba3ea4b7f98b3c403ed4bb102e65da3614ac5dea332e5b81616b469273f5f6912f3e690dac
data/bin/weight_converter CHANGED
@@ -2,4 +2,7 @@
2
2
 
3
3
  require 'weight_converter'
4
4
  weight = WeightConverter.new
5
- puts weight.hello(ARGV[0])
5
+
6
+
7
+
8
+ puts weight.convert(ARGV[0].to_f, ARGV[1].to_sym, ARGV[2].to_sym, ARGV[3].to_sym)
@@ -1,11 +1,40 @@
1
+ require 'colorize'
2
+
1
3
  class WeightConverter
2
- def hello(language)
3
- if language == "russian"
4
- puts "Привет"
5
- else
6
- puts "hello"
7
- end
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
- require 'weight_converter/random_class'
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
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
- - lib/weight_converter/random_class.rb
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
@@ -1,5 +0,0 @@
1
- class Weight
2
- def hi
3
- puts "hi"
4
- end
5
- end