0.0
No commit activity in last 3 years
No release in over 3 years
A SI prefix unit handling library for ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3.5
~> 0.9.12.2
~> 10.1.0
~> 2.14.1
 Project Readme

SI Prefix Units

A SI prefix unit handling library for ruby

Build Status

How it work's ?

Makes a parce of an absolute value and identifies the scale of the unit that belongs SI, returning the unit in better representation along with the unit symbol prefixed

Installation

Add in your application's Gemfile:

`gem "ruby-si-units", "~> 0.0.3"`

And using blunder, execute:

`$ bundle install`

Or install it yourself:

`$ gem install ruby-si-units`

Usage

Convert absolute value to a unit with prefix SI notation

unit = SIUnits::Unit.new 10000000
# => #<SIUnits::Unit:0x000000014be938 @value=10000000, @kind="mega">
unit.best_scale
# => 10.0
unit.to_s
# => "10.0 mega"
unit = SIUnits::Unit.new 0.000000001
# => #<SIUnits::Unit:0x000000014942a0 @value=1.0e-09, @kind="nano">
unit.best_scale
# => 1.0
unit.to_s
# => "1.0 nano"

Convert string to unit

"10.0k".to_unit
# => #<SIUnits::Unit:0x00000001bcbc30 @kind="kilo", @scale=1000.0, @value=10000.0>

"1n".to_unit
# => #<SIUnits::Unit:0x00000001bd1bd0 @kind="nano", @scale=1.0e-09, @value=1.0e-09>

Compare units

a = SIUnits::Unit.new 10000000
# => #<SIUnits::Unit:0x0000000283b8a8 @unit_value=10000000, @unit_kind="mega">

b = SIUnits::Unit.new 0.000000001
# => #<SIUnits::Unit:0x0000000272bb20 @unit_value=1.0e-09, @unit_kind="nano">

a > b
 => true
a < b
 => false
a <=> b
 => 1
a == b
 => false

Contributing

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

Another useful resources