Project

height

0.0
No commit activity in last 3 years
No release in over 3 years
Height support for metric and imperial systems
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
>= 0
 Project Readme

Height

Convert height between metric and imperial systems. The main target of this gem are apps that have to deal with human's height.

Installation

Add this line to your application's Gemfile:

gem 'height'

And then execute:

$ bundle

Or install it yourself as:

$ gem install height

Usage

@height = Height.new(191)

@height.millimeters # 1910
@height.centimeters # 191
@height.meters # 1.91
@height.feet # 6.25
@height.inches # 75

@height.to_s(:default, :metric) # '1m 91cm'
@height.to_s(:default, :imperial) # '6 ft 3 in'

# or simply:
@height.to_s # '1m 91cm'

I18n & Formats

The to_s method takes 2 optional arguments: :format and :system_of_units.

You can have as many formats as you like, add them into your locale file:

en:
  height:
    format:
      metric:
        default: '%{meters}m %{centimeters}cm'
        only_meters: '%{only_meters}m'
        only_centimeters: '%{only_centimeters}cm'

You can now call:

@height = Height.new(191)

@height.to_s(:default) # '1m 91cm'
@height.to_s(:only_meters) # '1.91m'
@height.to_s(:only_centimeters) # '191cm'

Same goes for the imperial system (:only_feet, :only_inches, etc).

System of units

You can specify which system of units(metric or imperial) you want when calling to_s:

Height.new(191).to_s(:default, :metric) # '1m 91cm'
Height.new(191).to_s(:default, :imperial) # '6 ft 3 in'

If you don't want to specify it every time, you can set it globally:

Height.system_of_units = :imperial

Height.new(191).to_s # '6 ft 3 in'

By default, system_of_units is :metric.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request