Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wasilak/bytes_converter
Gem converting Kilobytes, Megabytes and Gigabytes into bytes
https://github.com/wasilak/bytes_converter
Last synced: about 8 hours ago
JSON representation
Gem converting Kilobytes, Megabytes and Gigabytes into bytes
- Host: GitHub
- URL: https://github.com/wasilak/bytes_converter
- Owner: wasilak
- License: mit
- Created: 2013-01-17T22:21:05.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2024-04-25T17:46:34.000Z (7 months ago)
- Last Synced: 2024-04-26T14:38:34.722Z (7 months ago)
- Language: Ruby
- Size: 19.5 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# BytesConverter
[![Build Status](https://travis-ci.org/wasilak/bytes_converter.svg?branch=master)](https://travis-ci.org/wasilak/bytes_converter) [![Gem Version](https://badge.fury.io/rb/bytes_converter.svg)](http://badge.fury.io/rb/bytes_converter) [![Code Climate](https://codeclimate.com/github/wasilak/bytes_converter/badges/gpa.svg)](https://codeclimate.com/github/wasilak/bytes_converter)Gem converting Kilobytes, Megabytes and Gigabytes into bytes.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'bytes_converter'
```And then execute:
```
$ bundle
```Or install it yourself as:
```
$ gem install bytes_converter
```## Usage
first:
```ruby
require "bytes_converter"
```Converting strings to bytes:
```ruby
BytesConverter::convert "some string" # --> Float
```where "some string" can be anything like in these examples:
```ruby
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:
```ruby
orange = {"o" => 2}
BytesConverter::add_unit orange
```... and remove it with:
```ruby
BytesConverter::remove_unit "o"
```To get all available units:
```ruby
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