Skip to content

jlnwlf/speed_format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

speed_format: Bit rate for humans

Build Status Test Coverage Gem Version Code Climate

  • 💎 (MRI/JRuby) >= 1.9
  • Pure 💎, no dependencies.

Install

$ gem install speed_format

or used with Bundler:

gem 'speed_format'

or use the edge version from GitHub:

gem "speed_format", :git => "https://github.com/julienwolflisberg/speed_format.git"

Usage

require 'speed_format'

# Format to string
SpeedFormat::format_string("123")
 => "123 bit/s"
SpeedFormat::format_string("123000")
 => "123 kbit/s"
SpeedFormat::format_string("123000000")
 => "123 Mbit/s"
SpeedFormat::format_string("123000000000")
 => "123 Gbit/s"

# Or use prefixes...
SpeedFormat::format_string("0.0004", :M)
 => "400 bit/s"

# Otherwise get raw conversion...
SpeedFormat::format("123000000000")
 => [123, :G]

License

Copyright (C) 2016 Julien Wolflisberg

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.