convert_unit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +35 -0
  6. data/.travis.yml +5 -0
  7. data/AUTHORS +1 -0
  8. data/CHANGELOG.md +2 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/CONTRIBUTING.md +17 -0
  11. data/Gemfile +6 -0
  12. data/Gemfile.lock +69 -0
  13. data/LICENSE.txt +21 -0
  14. data/README.md +77 -0
  15. data/Rakefile +6 -0
  16. data/bin/console +14 -0
  17. data/bin/setup +8 -0
  18. data/convert_unit.gemspec +42 -0
  19. data/lib/convert_unit/area.rb +26 -0
  20. data/lib/convert_unit/base.rb +45 -0
  21. data/lib/convert_unit/convert_unit.rb +4 -0
  22. data/lib/convert_unit/length.rb +26 -0
  23. data/lib/convert_unit/mass.rb +26 -0
  24. data/lib/convert_unit/pre_process/area/conversion_rate.yml +42 -0
  25. data/lib/convert_unit/pre_process/area/process.rb +14 -0
  26. data/lib/convert_unit/pre_process/area/units.yml +6 -0
  27. data/lib/convert_unit/pre_process/area/units_symbol.yml +7 -0
  28. data/lib/convert_unit/pre_process/length/conversion_rate.yml +72 -0
  29. data/lib/convert_unit/pre_process/length/process.rb +14 -0
  30. data/lib/convert_unit/pre_process/length/units.yml +8 -0
  31. data/lib/convert_unit/pre_process/length/units_symbol.yml +8 -0
  32. data/lib/convert_unit/pre_process/load.rb +20 -0
  33. data/lib/convert_unit/pre_process/mass/conversion_rate.yml +56 -0
  34. data/lib/convert_unit/pre_process/mass/process.rb +14 -0
  35. data/lib/convert_unit/pre_process/mass/units.yml +7 -0
  36. data/lib/convert_unit/pre_process/mass/units_symbol.yml +7 -0
  37. data/lib/convert_unit/pre_process/volume/conversion_rate.yml +72 -0
  38. data/lib/convert_unit/pre_process/volume/process.rb +14 -0
  39. data/lib/convert_unit/pre_process/volume/units.yml +8 -0
  40. data/lib/convert_unit/pre_process/volume/units_symbol.yml +8 -0
  41. data/lib/convert_unit/version.rb +3 -0
  42. data/lib/convert_unit/volume.rb +26 -0
  43. data/lib/convert_unit.rb +2 -0
  44. metadata +160 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 739843d77196fb355a468ce92ca0fc2e93ecacc3
4
+ data.tar.gz: 3328a6cdd7021efed88b49a4820db2b37a0077b7
5
+ SHA512:
6
+ metadata.gz: fd53f11adfb7103876f51d5cb05ef16ad26cf179cb40a6a3b324ed83ab3c9b08a5542a7e4adc4ff3408fa5940d547e075f0557aa7f703d4363359d328989b39f
7
+ data.tar.gz: 18aa7124b5f96f158633b91664ffb80f2fab2625dcf124005f00eaa4c7a1e981d39ef8accce1acf97ac526eb15121486b9968ac7aa3b41b10c29d57af3fb40fd
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: Th5iszPMLMZKDcyuBJjEjJJIf8LrbZCqt
data/.gitignore ADDED
@@ -0,0 +1,12 @@
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
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,35 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+ - 'vendor/**/*'
5
+ - 'convert_unit.gemspec'
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
9
+
10
+ Metrics/MethodLength:
11
+ Max: 15
12
+
13
+ Style/BlockComments:
14
+ Enabled: false
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Layout/ExtraSpacing:
20
+ AllowForAlignment: true
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: false
24
+
25
+ Style/NumericLiterals:
26
+ Enabled: false
27
+
28
+ Style/Next:
29
+ Enabled: false
30
+
31
+ Naming/FileName:
32
+ Enabled: false
33
+
34
+ Style/CaseEquality:
35
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Tanir Hasan
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## v0.1.0
2
+ * initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tanvir002700@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,17 @@
1
+ # Contribution Guidelines
2
+
3
+ ## Steps
4
+
5
+ 1. Fork [the repo](https://github.com/tanvir002700/convert_unit)
6
+ 2. Grab dependencies: `bundle install`
7
+ 3. Make sure everything is working: `bundle exec rake spec`
8
+ 4. Make your changes
9
+ 5. Run your local from bin/console
10
+ 6. Test your changes
11
+ 7. Create a Pull Request
12
+ 8. Celebrate!!!!!
13
+
14
+ ## Notes
15
+
16
+ When contributing, please make sure to update the AUTHORS file
17
+ when you submit your pull request.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in convert_unit.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ convert_unit (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.3.0)
10
+ coveralls (0.8.21)
11
+ json (>= 1.8, < 3)
12
+ simplecov (~> 0.14.1)
13
+ term-ansicolor (~> 1.3)
14
+ thor (~> 0.19.4)
15
+ tins (~> 1.6)
16
+ diff-lcs (1.3)
17
+ docile (1.1.5)
18
+ json (2.1.0)
19
+ parallel (1.12.1)
20
+ parser (2.4.0.2)
21
+ ast (~> 2.3)
22
+ powerpack (0.1.1)
23
+ rainbow (3.0.0)
24
+ rake (10.5.0)
25
+ rspec (3.7.0)
26
+ rspec-core (~> 3.7.0)
27
+ rspec-expectations (~> 3.7.0)
28
+ rspec-mocks (~> 3.7.0)
29
+ rspec-core (3.7.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-expectations (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-mocks (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-support (3.7.0)
38
+ rubocop (0.52.0)
39
+ parallel (~> 1.10)
40
+ parser (>= 2.4.0.2, < 3.0)
41
+ powerpack (~> 0.1)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (~> 1.0, >= 1.0.1)
45
+ ruby-progressbar (1.9.0)
46
+ simplecov (0.14.1)
47
+ docile (~> 1.1.0)
48
+ json (>= 1.8, < 3)
49
+ simplecov-html (~> 0.10.0)
50
+ simplecov-html (0.10.2)
51
+ term-ansicolor (1.6.0)
52
+ tins (~> 1.0)
53
+ thor (0.19.4)
54
+ tins (1.16.3)
55
+ unicode-display_width (1.3.0)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler (~> 1.16)
62
+ convert_unit!
63
+ coveralls (~> 0.8.21)
64
+ rake (~> 10.0)
65
+ rspec (~> 3.0)
66
+ rubocop (~> 0.52.0)
67
+
68
+ BUNDLED WITH
69
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 tanvir hasan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # ConvertUnit
2
+ [![Build Status](https://travis-ci.org/tanvir002700/convert_unit.svg?branch=master)](https://travis-ci.org/tanvir002700/convert_unit)
3
+ [![Coverage Status](https://coveralls.io/repos/github/tanvir002700/convert_unit/badge.svg?branch=master)](https://coveralls.io/github/tanvir002700/convert_unit?branch=master)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/6e3e7ff7c7b040d1680d/maintainability)](https://codeclimate.com/github/tanvir002700/convert_unit/maintainability)
5
+ [![GitHub last commit (branch)](https://img.shields.io/github/last-commit/tanvir002700/convert_unit/master.svg)](https://github.com/tanvir002700/convert_unit)
6
+ [![license](https://img.shields.io/github/license/tanvir002700/convert_unit.svg)](https://github.com/tanvir002700/convert_unit/blob/master/LICENSE)
7
+
8
+ ## Introduction
9
+
10
+ A Ruby Library for dealing with different types of unit conversion.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'convert_unit'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install convert_unit
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require 'convert_unit'
32
+
33
+ meter = ConvertUnit::Length.new(1, 'km')
34
+ meter.to('km') #=> ConvertUnit::Length.new(1000, 'm')
35
+
36
+ # Comparisons
37
+ ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(1000, 'm') #=> true
38
+ ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(1, 'm') #=> false
39
+
40
+ ConvertUnit::Length.new(1, 'km') === ConvertUnit::Length.new(1, 'km') #=> true
41
+ ConvertUnit::Length.new(1, 'km') === ConvertUnit::Length.new(1000, 'm') #=> false
42
+
43
+ # Arithmetic
44
+ ConvertUnit::Length.new(1, 'km') + ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(2, 'km')
45
+ ConvertUnit::Length.new(1, 'km') + ConvertUnit::Length.new(1000, 'm') == ConvertUnit::Length.new(2, 'km')
46
+ ConvertUnit::Length.new(1000, 'm') + ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(2, 'm')
47
+
48
+ # Valid units argument list
49
+ ConvertUnit::Length::UNITS_SYMBOL #=> { "millimeter"=>"mm", "centimeter"=>"cm", "meter"=>"m",
50
+ # "kilometer"=>"km", "inche"=>"in", "feet"=>"ft", "yard"=>"yd",
51
+ # "mile"=>"mi" }
52
+ #
53
+ # both short and full form are accepted in argument and case insensitive.
54
+
55
+ ```
56
+
57
+ ## Available options for conversion
58
+
59
+ Name | Units
60
+ :---------:|:------------------------------:
61
+ Length | mm, cm, m, km, in, ft, yd, mi
62
+ Area | mm2, cm2, m2, in2, ft2, yd2
63
+ Mass | g, kg, tonne, sh_ton, l_ton, lb, oz
64
+ Volume | cm3, m3, ltr, in3, ft3, us_gal, imp_gal, us_brl
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tanvir002700/convert_unit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+ See the [Contribution Guidelines](https://github.com/tanvir002700/convert_unit/blob/master/CONTRIBUTING.md)
69
+
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
+
75
+ ## Code of Conduct
76
+
77
+ Everyone interacting in the ConvertUnit project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tanvir002700/convert_unit/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "convert_unit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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,42 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+ #
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'convert_unit/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'convert_unit'
10
+ spec.version = ConvertUnit::VERSION
11
+ spec.authors = ['tanvir hasan']
12
+ spec.email = ['tanvir002700@gmail.com']
13
+
14
+ spec.summary = 'A simple unit conversion gem.'
15
+ spec.description = 'A Ruby Library for dealing with different types of unit conversion, \
16
+ with Arithmetic operation and comparisons.'
17
+ spec.homepage = 'https://rubygems.org/gems/convert_unit'
18
+ spec.license = 'MIT'
19
+ spec.metadata = { 'source_code_uri' => 'https://github.com/tanvir002700/convert_unit' }
20
+
21
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
22
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
25
+ else
26
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
27
+ 'public gem pushes.'
28
+ end
29
+
30
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
31
+ f.match(%r{^(test|spec|features)/})
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ spec.add_development_dependency 'bundler', '~> 1.16'
38
+ spec.add_development_dependency 'coveralls', '~> 0.8.21'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'rubocop', '~> 0.52.0'
42
+ end
@@ -0,0 +1,26 @@
1
+ require 'convert_unit/base'
2
+ require 'convert_unit/pre_process/area/process'
3
+
4
+ module ConvertUnit
5
+ class Area < Base
6
+ extend PreProcess::Area
7
+ UNITS_SYMBOL = load_units_symbol
8
+ UNITS = load_available_units
9
+ CONVERSION_RATE = load_conversion_rate
10
+
11
+ attr_accessor :value, :unit
12
+
13
+ def initialize(value, unit)
14
+ unit_symbol = Area::UNITS_SYMBOL[unit] || unit
15
+ @conversion_rate_for_one_unit = Area::CONVERSION_RATE
16
+ super(value, unit_symbol, Area::UNITS)
17
+ end
18
+
19
+ def to(c_unit)
20
+ c_unit.downcase!
21
+ unit_symbol = Area::UNITS_SYMBOL[c_unit] || c_unit
22
+ raise ArgumentError, 'Unpossible conversion type' unless Area::UNITS.include?(unit_symbol)
23
+ Area.new(convert_to(unit_symbol), unit_symbol)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ class Base
2
+ attr_accessor :value, :unit
3
+
4
+ def initialize(value, unit, valid_units)
5
+ raise TypeError, 'no implicit conversion of String into Integer' unless value.is_a? Numeric
6
+ raise TypeError, 'Invalid Unit Type' unless valid_units.include?(unit.to_s.downcase)
7
+ @value = value
8
+ @unit = unit.downcase
9
+ end
10
+
11
+ def ==(other)
12
+ a_to_b = one_unit_a_to_b(unit, other.unit) * value
13
+ b_to_a = one_unit_a_to_b(other.unit, unit) * other.value
14
+ a_to_b == other.value || b_to_a == value
15
+ end
16
+
17
+ def ===(other)
18
+ value == other.value && unit == other.unit
19
+ end
20
+
21
+ def +(other)
22
+ b_to_a = other.to(unit)
23
+ self.class.new(value + b_to_a.value, unit)
24
+ end
25
+
26
+ def -(other)
27
+ b_to_a = other.to(unit)
28
+ self.class.new(value - b_to_a.value, unit)
29
+ end
30
+
31
+ def inspect
32
+ "#{@value}#{@unit}"
33
+ end
34
+
35
+ protected
36
+
37
+ def one_unit_a_to_b(unit_a, unit_b)
38
+ conversion_rate = @conversion_rate_for_one_unit[unit_a][unit_b]
39
+ format('%<value>f', value: conversion_rate).to_f
40
+ end
41
+
42
+ def convert_to(c_unit)
43
+ one_unit_a_to_b(unit, c_unit) * value
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ require 'convert_unit/length'
2
+ require 'convert_unit/area'
3
+ require 'convert_unit/mass'
4
+ require 'convert_unit/volume'
@@ -0,0 +1,26 @@
1
+ require 'convert_unit/base'
2
+ require 'convert_unit/pre_process/length/process'
3
+
4
+ module ConvertUnit
5
+ class Length < Base
6
+ extend PreProcess::Length
7
+ UNITS_SYMBOL = load_units_symbol
8
+ UNITS = load_available_units
9
+ CONVERSION_RATE = load_conversion_rate
10
+
11
+ attr_accessor :value, :unit
12
+
13
+ def initialize(value, unit)
14
+ unit_symbol = Length::UNITS_SYMBOL[unit] || unit
15
+ @conversion_rate_for_one_unit = Length::CONVERSION_RATE
16
+ super(value, unit_symbol, Length::UNITS)
17
+ end
18
+
19
+ def to(c_unit)
20
+ c_unit.downcase!
21
+ unit_symbol = Length::UNITS_SYMBOL[c_unit] || c_unit
22
+ raise ArgumentError, 'Unpossible conversion type' unless Length::UNITS.include?(unit_symbol)
23
+ Length.new(convert_to(unit_symbol), unit_symbol)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'convert_unit/base'
2
+ require 'convert_unit/pre_process/mass/process'
3
+
4
+ module ConvertUnit
5
+ class Mass < Base
6
+ extend PreProcess::Mass
7
+ UNITS_SYMBOL = load_units_symbol
8
+ UNITS = load_available_units
9
+ CONVERSION_RATE = load_conversion_rate
10
+
11
+ attr_accessor :value, :unit
12
+
13
+ def initialize(value, unit)
14
+ unit_symbol = Mass::UNITS_SYMBOL[unit] || unit
15
+ @conversion_rate_for_one_unit = Mass::CONVERSION_RATE
16
+ super(value, unit_symbol, Mass::UNITS)
17
+ end
18
+
19
+ def to(c_unit)
20
+ c_unit.downcase!
21
+ unit_symbol = Mass::UNITS_SYMBOL[c_unit] || c_unit
22
+ raise ArgumentError, 'Unpossible conversion type' unless Mass::UNITS.include?(unit_symbol)
23
+ Mass.new(convert_to(unit_symbol), unit_symbol)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,42 @@
1
+ mm2:
2
+ mm2: 1
3
+ cm2: 1e-2
4
+ m2: 1e-6
5
+ in2: 0.00155
6
+ ft2: 0.000011
7
+ yd2: 0.000001
8
+ cm2:
9
+ mm2: 1e2
10
+ cm2: 1
11
+ m2: 1e-4
12
+ in2: 0.155
13
+ ft2: 0.001076
14
+ yd2: 0.00012
15
+ m2:
16
+ mm2: 1e6
17
+ cm2: 1e4
18
+ m2: 1
19
+ in2: 1550.003
20
+ ft2: 10.76391
21
+ yd2: 1.19599
22
+ in2:
23
+ mm2: 645.16
24
+ cm2: 6.4516
25
+ m2: 0.000645
26
+ in2: 1
27
+ ft2: 0.006944
28
+ yd2: 0.000772
29
+ ft2:
30
+ mm2: 92903
31
+ cm2: 929.0304
32
+ m2: 0.092903
33
+ in2: 144
34
+ ft2: 1
35
+ yd2: 0.111111
36
+ yd2:
37
+ mm2: 836127
38
+ cm2: 8361.274
39
+ m2: 0.836127
40
+ in2: 1296
41
+ ft2: 9
42
+ yd2: 1
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'convert_unit/pre_process/load'
3
+
4
+ module ConvertUnit
5
+ module PreProcess
6
+ module Area
7
+ include ConvertUnit::PreProcess
8
+
9
+ def file_path
10
+ File.dirname(__FILE__)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ - mm2
2
+ - cm2
3
+ - m2
4
+ - in2
5
+ - ft2
6
+ - yd2
@@ -0,0 +1,7 @@
1
+ meter_square: mm2
2
+ centimeter_square: cm2
3
+ meter_square: m2
4
+ inch_square: in2
5
+ foot_square: ft2
6
+ yard_square: yd2
7
+
@@ -0,0 +1,72 @@
1
+ mm:
2
+ mm: 1
3
+ cm: 1e-1
4
+ m: 1e-3
5
+ km: 1e-6
6
+ in: 0.03937
7
+ ft: 0.003281
8
+ yd: 0.001094
9
+ mi: 6.21e-07
10
+ cm:
11
+ mm: 1e1
12
+ cm: 1
13
+ m: 1e-2
14
+ km: 1e-5
15
+ in: 0.393701
16
+ ft: 0.032808
17
+ yd: 0.010936
18
+ mi: 6e-6
19
+ m:
20
+ mm: 1e3
21
+ cm: 1e2
22
+ m: 1
23
+ km: 1e-3
24
+ in: 93.37008
25
+ ft: 3.28084
26
+ yd: 1.093613
27
+ mi: 0.000621
28
+ km:
29
+ mm: 1e6
30
+ cm: 1e5
31
+ m: 1e3
32
+ km: 1
33
+ in: 39370.08
34
+ ft: 3280.84
35
+ yd: 1093.613
36
+ mi: 0.621371
37
+ in:
38
+ mm: 25.4
39
+ cm: 2.54
40
+ m: 0.0254
41
+ km: 0.000025
42
+ in: 1
43
+ ft: 0.083333
44
+ yd: 0.027778
45
+ mi: 0.000016
46
+ ft:
47
+ mm: 304.8
48
+ cm: 30.48
49
+ m: 0.3048
50
+ km: 0.000305
51
+ in: 12
52
+ ft: 1
53
+ yd: 0.333333
54
+ mi: 0.000189
55
+ yd:
56
+ mm: 914.4
57
+ cm: 91.44
58
+ m: 0.9144
59
+ km: 0.000914
60
+ in: 36
61
+ ft: 3
62
+ yd: 1
63
+ mi: 0.000568
64
+ mi:
65
+ mm: 1609344
66
+ cm: 160934.4
67
+ m: 1609.344
68
+ km: 1.609344
69
+ in: 63360
70
+ ft: 5280
71
+ yd: 1760
72
+ mi: 1
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'convert_unit/pre_process/load'
3
+
4
+ module ConvertUnit
5
+ module PreProcess
6
+ module Length
7
+ include ConvertUnit::PreProcess
8
+
9
+ def file_path
10
+ File.dirname(__FILE__)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ - mm
2
+ - cm
3
+ - m
4
+ - km
5
+ - in
6
+ - ft
7
+ - yd
8
+ - mi
@@ -0,0 +1,8 @@
1
+ millimeter: mm
2
+ centimeter: cm
3
+ meter: m
4
+ kilometer: km
5
+ inche: in
6
+ feet: ft
7
+ yard: yd
8
+ mile: mi
@@ -0,0 +1,20 @@
1
+ module ConvertUnit
2
+ module PreProcess
3
+ def file_path; end
4
+
5
+ def load_units_symbol
6
+ f = File.open(File.join(file_path, 'units_symbol.yml'))
7
+ YAML.safe_load(f)
8
+ end
9
+
10
+ def load_available_units
11
+ f = File.open(File.join(file_path, 'units.yml'))
12
+ YAML.safe_load(f)
13
+ end
14
+
15
+ def load_conversion_rate
16
+ f = File.open(File.join(file_path, 'conversion_rate.yml'))
17
+ YAML.safe_load(f)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,56 @@
1
+ g:
2
+ g: 1
3
+ kg: 0.001
4
+ tonne: 0.000001
5
+ sh_ton: 0.000001
6
+ l_ton: 9.84e-07
7
+ lb: 0.002205
8
+ oz: 0.035273
9
+ kg:
10
+ g: 1000
11
+ kg: 1
12
+ tonne: 0.001
13
+ sh_ton: 0.001102
14
+ l_ton: 0.000984
15
+ lb: 2.204586
16
+ oz: 35.27337
17
+ tonne:
18
+ g: 1000000
19
+ kg: 1000
20
+ tonne: 1
21
+ sh_ton: 1.102293
22
+ l_ton: 0.984252
23
+ lb: 2204.586
24
+ oz: 35273.37
25
+ sh_ton:
26
+ g: 907200
27
+ kg: 907.2
28
+ tonne: 0.9072
29
+ sh_ton: 1
30
+ l_ton: 0.892913
31
+ lb: 2000
32
+ oz: 32000
33
+ l_ton:
34
+ g: 1016000
35
+ kg: 1016
36
+ tonne: 1.016
37
+ sh_ton: 1.119929
38
+ l_ton: 1
39
+ lb: 2239.859
40
+ oz: 35837.74
41
+ lb:
42
+ g: 453.6
43
+ kg: 0.4536
44
+ tonne: 0.000454
45
+ sh_ton: 0.0005
46
+ l_ton: 0.000446
47
+ lb: 1
48
+ oz: 16
49
+ oz:
50
+ g: 28
51
+ kg: 0.02835
52
+ tonne: 0.000028
53
+ sh_ton: 0.000031
54
+ l_ton: 0.000028
55
+ lb: 0.0625
56
+ oz: 1
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'convert_unit/pre_process/load'
3
+
4
+ module ConvertUnit
5
+ module PreProcess
6
+ module Mass
7
+ include ConvertUnit::PreProcess
8
+
9
+ def file_path
10
+ File.dirname(__FILE__)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ - g
2
+ - kg
3
+ - tonne
4
+ - sh_ton
5
+ - l_ton
6
+ - lb
7
+ - oz
@@ -0,0 +1,7 @@
1
+ grams: g
2
+ kilograms: kg
3
+ metric_tonnes: tonne
4
+ short_ton: sh_ton
5
+ long_ton: l_ton
6
+ pounds: lb
7
+ ounces: oz
@@ -0,0 +1,72 @@
1
+ cm3:
2
+ cm3: 1
3
+ m3: 0.000001
4
+ ltr: 0.001
5
+ in3: 0.061024
6
+ ft3: 0.000035
7
+ us_gal: 0.000264
8
+ imp_gal: 0.00022
9
+ us_brl: 0.000006
10
+ m3:
11
+ cm3: 1000000
12
+ m3: 1
13
+ ltr: 1000
14
+ in3: 61024
15
+ ft3: 35
16
+ us_gal: 264
17
+ imp_gal: 220
18
+ us_brl: 6.29
19
+ ltr:
20
+ cm3: 1000
21
+ m3: 0.001
22
+ ltr: 1
23
+ in3: 61
24
+ ft3: 0.035
25
+ us_gal: 0.264201
26
+ imp_gal: 0.22
27
+ us_brl: 0.00629
28
+ in3:
29
+ cm3: 16.4
30
+ m3: 0.000016
31
+ ltr: 0.016387
32
+ in3: 1
33
+ ft3: 0.000579
34
+ us_gal: 0.004329
35
+ imp_gal: 0.003605
36
+ us_brl: 0.000103
37
+ ft3:
38
+ cm3: 28317
39
+ m3: 0.028317
40
+ ltr: 28.31685
41
+ in3: 1728
42
+ ft3: 1
43
+ us_gal: 7.481333
44
+ imp_gal: 6.229712
45
+ us_brl: 0.178127
46
+ us_gal:
47
+ cm3: 3785
48
+ m3: 0.003785
49
+ ltr: 3.79
50
+ in3: 231
51
+ ft3: 0.13
52
+ us_gal: 1
53
+ imp_gal: 0.832701
54
+ us_brl: 0.02381
55
+ imp_gal:
56
+ cm3: 4545
57
+ m3: 0.004545
58
+ ltr: 4.55
59
+ in3: 277
60
+ ft3: 0.16
61
+ us_gal: 1.20
62
+ imp_gal: 1
63
+ us_brl: 0.028593
64
+ cm3:
65
+ cm3: 158970
66
+ m3: 0.15897
67
+ ltr: 159
68
+ in3: 9701
69
+ ft3: 6
70
+ us_gal: 42
71
+ imp_gal: 35
72
+ us_brl: 1
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'convert_unit/pre_process/load'
3
+
4
+ module ConvertUnit
5
+ module PreProcess
6
+ module Volume
7
+ include ConvertUnit::PreProcess
8
+
9
+ def file_path
10
+ File.dirname(__FILE__)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ - cm3
2
+ - m3
3
+ - ltr
4
+ - in3
5
+ - ft3
6
+ - us_gal
7
+ - imp_gal
8
+ - us_brl
@@ -0,0 +1,8 @@
1
+ centimeter_cube: cm3
2
+ meter_cube: m3
3
+ liter: ltr
4
+ inch_cube: in3
5
+ foot_cube: ft3
6
+ uS_gallons: us_gal
7
+ imperial_gallons: imp_gal
8
+ uS_barrel: us_bal
@@ -0,0 +1,3 @@
1
+ module ConvertUnit
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'convert_unit/base'
2
+ require 'convert_unit/pre_process/volume/process'
3
+
4
+ module ConvertUnit
5
+ class Volume < Base
6
+ extend PreProcess::Volume
7
+ UNITS_SYMBOL = load_units_symbol
8
+ UNITS = load_available_units
9
+ CONVERSION_RATE = load_conversion_rate
10
+
11
+ attr_accessor :value, :unit
12
+
13
+ def initialize(value, unit)
14
+ unit_symbol = Volume::UNITS_SYMBOL[unit] || unit
15
+ @conversion_rate_for_one_unit = Volume::CONVERSION_RATE
16
+ super(value, unit_symbol, Volume::UNITS)
17
+ end
18
+
19
+ def to(c_unit)
20
+ c_unit.downcase!
21
+ unit_symbol = Volume::UNITS_SYMBOL[c_unit] || c_unit
22
+ raise ArgumentError, 'Unpossible conversion type' unless Volume::UNITS.include?(unit_symbol)
23
+ Volume.new(convert_to(unit_symbol), unit_symbol)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,2 @@
1
+ require 'convert_unit/version'
2
+ require 'convert_unit/convert_unit'
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: convert_unit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tanvir hasan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.21
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.21
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.52.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.52.0
83
+ description: |-
84
+ A Ruby Library for dealing with different types of unit conversion, \
85
+ with Arithmetic operation and comparisons.
86
+ email:
87
+ - tanvir002700@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".coveralls.yml"
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".rubocop.yml"
96
+ - ".travis.yml"
97
+ - AUTHORS
98
+ - CHANGELOG.md
99
+ - CODE_OF_CONDUCT.md
100
+ - CONTRIBUTING.md
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - bin/console
107
+ - bin/setup
108
+ - convert_unit.gemspec
109
+ - lib/convert_unit.rb
110
+ - lib/convert_unit/area.rb
111
+ - lib/convert_unit/base.rb
112
+ - lib/convert_unit/convert_unit.rb
113
+ - lib/convert_unit/length.rb
114
+ - lib/convert_unit/mass.rb
115
+ - lib/convert_unit/pre_process/area/conversion_rate.yml
116
+ - lib/convert_unit/pre_process/area/process.rb
117
+ - lib/convert_unit/pre_process/area/units.yml
118
+ - lib/convert_unit/pre_process/area/units_symbol.yml
119
+ - lib/convert_unit/pre_process/length/conversion_rate.yml
120
+ - lib/convert_unit/pre_process/length/process.rb
121
+ - lib/convert_unit/pre_process/length/units.yml
122
+ - lib/convert_unit/pre_process/length/units_symbol.yml
123
+ - lib/convert_unit/pre_process/load.rb
124
+ - lib/convert_unit/pre_process/mass/conversion_rate.yml
125
+ - lib/convert_unit/pre_process/mass/process.rb
126
+ - lib/convert_unit/pre_process/mass/units.yml
127
+ - lib/convert_unit/pre_process/mass/units_symbol.yml
128
+ - lib/convert_unit/pre_process/volume/conversion_rate.yml
129
+ - lib/convert_unit/pre_process/volume/process.rb
130
+ - lib/convert_unit/pre_process/volume/units.yml
131
+ - lib/convert_unit/pre_process/volume/units_symbol.yml
132
+ - lib/convert_unit/version.rb
133
+ - lib/convert_unit/volume.rb
134
+ homepage: https://rubygems.org/gems/convert_unit
135
+ licenses:
136
+ - MIT
137
+ metadata:
138
+ source_code_uri: https://github.com/tanvir002700/convert_unit
139
+ allowed_push_host: https://rubygems.org
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.6.11
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: A simple unit conversion gem.
160
+ test_files: []