0.01
No release in over 3 years
Low commit activity in last 3 years
Gem converting Kilobytes, Megabytes and Gigabytes to bytes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

BytesConverter

Build Status Gem Version Code Climate

Gem converting Kilobytes, Megabytes and Gigabytes into bytes.

Installation

Add this line to your application's Gemfile:

gem 'bytes_converter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bytes_converter

Usage

first:

require "bytes_converter"

Converting strings to bytes:

BytesConverter::convert "some string" # --> Float

where "some string" can be anything like in these examples:

BytesConverter::convert "12.3M" # --> 12897484.8
BytesConverter::convert "12.3" # --> 12.3 (no unit means bytes)
BytesConverter::convert "12.3 kilo bytes" # --> 12595.2
BytesConverter::convert "12.3 Megabytes" # --> 12897484.8
BytesConverter::convert "12.3 m" # --> 12897484.8
BytesConverter::convert "12.3 k" # --> 12595.2
BytesConverter::convert "12.3 bk" # --> 0.0 (b is not recognized)
BytesConverter::convert "12,3m" # --> 12897484.8
BytesConverter::convert "123" # --> 123

You can add new unit as a hash. Let's say you want OrangeBytes unit:

orange = {"o" => 2}
BytesConverter::add_unit orange

... and remove it with:

BytesConverter::remove_unit "o"

To get all available units:

BytesConverter::get_units # --> Hash

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