ts_convertor 0.1.4

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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4b0385181c2695cc3e95ee87e70e42928c58d611a22b8274c1e727f815659f5
4
+ data.tar.gz: 87be4988828863a966a1c2d400ee70e5d3526f1340f32b74b99e922eb13c66a4
5
+ SHA512:
6
+ metadata.gz: d2b2190af5e180ec0eac02debc807e2fd335a1df7ff22c72e7af954e9db48b6424d2dea0e80241dcc029e1f9e51ae1d2791650fe0c2f28bf56625578234fe0e9
7
+ data.tar.gz: 339ec461c97c0f0bd7fae84ef0fc6ddfed7e32730db2d419577cddc53c107d7039a7ffbfbe40dde5d2ab49522a506d94e1fa76df89981fb5ef5103e7843d2af9
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Documentation:
4
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in ts_convertor.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rubocop'
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ts_convertor (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.4.4)
11
+ parallel (1.20.1)
12
+ parser (3.0.0.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (12.3.3)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.4)
18
+ rspec (3.10.0)
19
+ rspec-core (~> 3.10.0)
20
+ rspec-expectations (~> 3.10.0)
21
+ rspec-mocks (~> 3.10.0)
22
+ rspec-core (3.10.1)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-expectations (3.10.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-mocks (3.10.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-support (3.10.2)
31
+ rubocop (1.11.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.0.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.2.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.4.1)
41
+ parser (>= 2.7.1.5)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.0.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ rake (~> 12.0)
50
+ rspec (~> 3.0)
51
+ rubocop
52
+ ts_convertor!
53
+
54
+ BUNDLED WITH
55
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # TsConvertor
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ts_convertor`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ts_convertor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ts_convertor
22
+
23
+ add to your project
24
+
25
+ ```ruby
26
+ require 'ts_convertor'
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ In version 0.1.3 is valid `Speed`, `Weight`, `Length` convertors
32
+
33
+ To convert
34
+
35
+ ```
36
+ TsConvertor.[metric]_convert(amount, [var1], [var2])
37
+ ```
38
+
39
+ metric = `speed` , vars = `%w[km_h km_m mile_h mile_m knots]`
40
+
41
+ metric = `weight` , vars = `%w[kg pound ton gram]`
42
+
43
+ metric = `length` , vars = `%w[km mile meter yard foot]`
44
+
45
+ example
46
+
47
+ ```ruby
48
+ result = TsConvertor.speed_convert(60, 'km_h', 'mile_h')
49
+
50
+ result.eql?(37.2822714)
51
+ ```
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ts_convertor.
62
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ts_convertor'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ts_convertor/version'
4
+ require 'ts_convertor/speed'
5
+ require 'ts_convertor/weight'
6
+ require 'ts_convertor/length'
7
+
8
+ module TsConvertor
9
+ class Error < StandardError; end
10
+
11
+ METHODS = %w[speed weight length].freeze
12
+
13
+ class << self
14
+ METHODS.each do |method|
15
+ define_method "#{method}_convert" do |val, from, to|
16
+ current_object = Object.const_get("TsConvertor::#{method.capitalize}").new(from, to)
17
+ current_object.convert(val)
18
+ rescue StandardError
19
+ raise Error, "Can not convert #{method} !!!"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TsConvertor
4
+ module Config
5
+ def check_variables(size)
6
+ raise Error, "FROM variable is undefined, valid variables = #{size}" unless size.include?(from)
7
+ raise Error, "TO variable is undefined, valid variables = #{size}" unless size.include?(to)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ts_convertor/config'
4
+
5
+ module TsConvertor
6
+ class Length
7
+ include Config
8
+
9
+ SIZE = %w[km mile meter yard foot].freeze
10
+
11
+ attr_reader :from, :to
12
+
13
+ def initialize(from, to)
14
+ @from = from
15
+ @to = to
16
+ end
17
+
18
+ def convert(val)
19
+ check_variables(SIZE)
20
+ val * send(from)
21
+ end
22
+
23
+ private
24
+
25
+ def km
26
+ return 1 if to.eql?('km')
27
+ return 0.62137119 if to.eql?('mile')
28
+ return 1000 if to.eql?('meter')
29
+ return 1093.6133 if to.eql?('yard')
30
+ return 3280.8399 if to.eql?('foot')
31
+ end
32
+
33
+ def mile
34
+ return 1 if to.eql?('mile')
35
+ return 1.609344 if to.eql?('km')
36
+ return 1609.344 if to.eql?('meter')
37
+ return 1760 if to.eql?('yard')
38
+ return 5280 if to.eql?('foot')
39
+ end
40
+
41
+ def meter
42
+ return 1 if to.eql?('meter')
43
+ return 0.001 if to.eql?('km')
44
+ return 0.0062137 if to.eql?('mile')
45
+ return 1.0936133 if to.eql?('yard')
46
+ return 3.2808399 if to.eql?('foot')
47
+ end
48
+
49
+ def yard
50
+ return 1 if to.eql?('yard')
51
+ return 0.0009144 if to.eql?('km')
52
+ return 0.0005682 if to.eql?('mile')
53
+ return 0.9144 if to.eql?('meter')
54
+ return 3 if to.eql?('foot')
55
+ end
56
+
57
+ def foot
58
+ return 1 if to.eql?('foot')
59
+ return 0.0003048 if to.eql?('km')
60
+ return 0.00018939394 if to.eql?('mile')
61
+ return 0.3048 if to.eql?('meter')
62
+ return 0.33333333 if to.eql?('yard')
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ts_convertor/config'
4
+
5
+ module TsConvertor
6
+ class Speed
7
+ include Config
8
+
9
+ SIZE = %w[km_h km_m mile_h mile_m knots].freeze
10
+
11
+ attr_reader :from, :to
12
+
13
+ def initialize(from, to)
14
+ @from = from
15
+ @to = to
16
+ end
17
+
18
+ def convert(val)
19
+ check_variables(SIZE)
20
+ val * send(from)
21
+ end
22
+
23
+ private
24
+
25
+ def km_h
26
+ return 1 if to.eql?('km_h')
27
+ return 0.016666667 if to.eql?('km_m')
28
+ return 0.62137119 if to.eql?('mile_h')
29
+ return 0.010356187 if to.eql?('mile_m')
30
+ return 0.5399568 if to.eql?('knots')
31
+ end
32
+
33
+ def km_m
34
+ return 1 if to.eql?('km_m')
35
+ return 60 if to.eql?('km_h')
36
+ return 37.282272 if to.eql?('mile_h')
37
+ return 0.62137119 if to.eql?('mile_m')
38
+ return 32.397408 if to.eql?('knots')
39
+ end
40
+
41
+ def mile_h
42
+ return 1 if to.eql?('mile_h')
43
+ return 1.609344 if to.eql?('km_h')
44
+ return 0.0268224 if to.eql?('km_m')
45
+ return 0.016666667 if to.eql?('mile_m')
46
+ return 0.86897624 if to.eql?('knots')
47
+ end
48
+
49
+ def mile_m
50
+ return 1 if to.eql?('mile_m')
51
+ return 96.56064 if to.eql?('km_h')
52
+ return 1.609344 if to.eql?('km_m')
53
+ return 60 if to.eql?('mile_h')
54
+ return 52.138574 if to.eql?('knots')
55
+ end
56
+
57
+ def knots
58
+ return 1 if to.eql?('knots')
59
+ return 1.852 if to.eql?('km_h')
60
+ return 0.030866667 if to.eql?('km_m')
61
+ return 1.1507794 if to.eql?('mile_h')
62
+ return 0.019179657 if to.eql?('mile_m')
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TsConvertor
4
+ VERSION = '0.1.4'
5
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ts_convertor/config'
4
+
5
+ module TsConvertor
6
+ class Weight
7
+ include Config
8
+
9
+ SIZE = %w[kg pound ton gram].freeze
10
+
11
+ attr_reader :from, :to
12
+
13
+ def initialize(from, to)
14
+ @from = from
15
+ @to = to
16
+ end
17
+
18
+ def convert(val)
19
+ check_variables(SIZE)
20
+ val * send(from)
21
+ end
22
+
23
+ private
24
+
25
+ def kg
26
+ return 1 if to.eql?('kg')
27
+ return 1000 if to.eql?('gram')
28
+ return 0.001 if to.eql?('ton')
29
+ return 2.2046226 if to.eql?('pound')
30
+ end
31
+
32
+ def gram
33
+ return 1 if to.eql?('gram')
34
+ return 0.001 if to.eql?('gram')
35
+ return 0.00001 if to.eql?('ton')
36
+ return 0.0022046226 if to.eql?('pound')
37
+ end
38
+
39
+ def ton
40
+ return 1 if to.eql?('ton')
41
+ return 1000 if to.eql?('kg')
42
+ return 1_000_000 if to.eql?('gram')
43
+ return 2204.6226 if to.eql?('pound')
44
+ end
45
+
46
+ def pound
47
+ return 1 if to.eql?('pound')
48
+ return 0.45359237 if to.eql?('kg')
49
+ return 453.59237 if to.eql?('gram')
50
+ return 0.00045359237 if to.eql?('ton')
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/ts_convertor/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ts_convertor'
7
+ spec.version = TsConvertor::VERSION
8
+ spec.authors = ['sypataras']
9
+ spec.email = ['sypenko88@gmail.com']
10
+
11
+ spec.summary = 'convertor'
12
+ spec.description = 'convert all metrics'
13
+ spec.homepage = 'https://rubygems.org/gems/ts_convertor'
14
+ spec.required_ruby_version = '>= 2.6.0'
15
+
16
+ #spec.metadata['allowed_push_host'] = 'https://github.com/sypataras/ts_convertor'
17
+
18
+ #spec.metadata['homepage_uri'] = spec.homepage
19
+ #spec.metadata['source_code_uri'] = 'https://github.com/sypataras/ts_convertor'
20
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ts_convertor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - sypataras
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: convert all metrics
14
+ email:
15
+ - sypenko88@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - ".travis.yml"
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - lib/ts_convertor.rb
31
+ - lib/ts_convertor/config.rb
32
+ - lib/ts_convertor/length.rb
33
+ - lib/ts_convertor/speed.rb
34
+ - lib/ts_convertor/version.rb
35
+ - lib/ts_convertor/weight.rb
36
+ - ts_convertor.gemspec
37
+ homepage: https://rubygems.org/gems/ts_convertor
38
+ licenses: []
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.6.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.4
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: convertor
59
+ test_files: []