0.0
No commit activity in last 3 years
No release in over 3 years
A Ruby Library for dealing with different types of unit conversion, \ with Arithmetic operation and comparisons.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 0.8.21
~> 10.0
~> 3.0
~> 0.52.0
 Project Readme

ConvertUnit

Build Status Coverage Status Maintainability Gem Version Downloads GitHub last commit (branch) license

Introduction

A Ruby Library for dealing with different types of unit conversion.

Installation

Add this line to your application's Gemfile:

gem 'convert_unit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install convert_unit

Usage

require 'convert_unit'

meter = ConvertUnit::Length.new(1, 'km')
meter.to('km') #=> ConvertUnit::Length.new(1000, 'm')

# Comparisons
ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(1000, 'm')  #=> true
ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(1, 'm')     #=> false

ConvertUnit::Length.new(1, 'km') === ConvertUnit::Length.new(1, 'km')   #=> true
ConvertUnit::Length.new(1, 'km') === ConvertUnit::Length.new(1000, 'm') #=> false

# Arithmetic
ConvertUnit::Length.new(1, 'km') + ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(2, 'km')
ConvertUnit::Length.new(1, 'km') + ConvertUnit::Length.new(1000, 'm') == ConvertUnit::Length.new(2, 'km')
ConvertUnit::Length.new(1000, 'm') + ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(2000, 'm')
ConvertUnit::Length.new(1000, 'm') - ConvertUnit::Length.new(1, 'km') == ConvertUnit::Length.new(0, 'm')

# Valid units argument list
ConvertUnit::Length::UNITS_SYMBOL       #=> { "millimeter"=>"mm", "centimeter"=>"cm", "meter"=>"m",
                                        #     "kilometer"=>"km", "inche"=>"in", "feet"=>"ft", "yard"=>"yd", 
                                        #     "mile"=>"mi" }
                                        #
                                        # both short and full form are accepted in argument and case insensitive.

Available options for conversion

Name Units
Length mm, cm, m, km, in, ft, yd, mi
Area mm2, cm2, m2, in2, ft2, yd2
Mass g, kg, tonne, sh_ton, l_ton, lb, oz
Volume cm3, m3, ltr, in3, ft3, us_gal, imp_gal, us_brl
Density g/ml kg/m3 lb/ft3 lb/in3
Volumetric Liquid flow l/sec l/min m3 ft3/min ft3/hr gal/min brl/d
Volumetric Liquid flow nm3/hr scfh scfm
Mass Flow kg/h lb/h kg/s t/h
High Pressure bar psi kpa mpa kgf/cm2 mm_hg atm
Low Pressure mh2o fth2o cmhg inhg inh2o pa
KinematicViscosity cs st ft2/s m2/s
Speed m/s m/min km/h ft/s ft/min mi/h
DynamicViscosity cp poise lb/ft·s
Torque nm kgfm ftlb inlb

Contributing

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 code of conduct. See the Contribution Guidelines

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the ConvertUnit project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.