bytes_converter 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +44 -1
- data/lib/bytes_converter.rb +1 -4
- data/lib/bytes_converter/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -18,7 +18,50 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
first:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "bytes_converter"
|
25
|
+
```
|
26
|
+
|
27
|
+
Converting strings to bytes:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
BytesConverter::convert "some string" # --> Float
|
31
|
+
```
|
32
|
+
|
33
|
+
where "some string" can be anything like in these examples:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
BytesConverter::convert "12.3M" # --> 12897484.8
|
37
|
+
BytesConverter::convert "12.3" # --> 12.3 (no unit means bytes)
|
38
|
+
BytesConverter::convert "12.3 kilo bytes" # --> 12595.2
|
39
|
+
BytesConverter::convert "12.3 Megabytes" # --> 12897484.8
|
40
|
+
BytesConverter::convert "12.3 m" # --> 12897484.8
|
41
|
+
BytesConverter::convert "12.3 k" # --> 12595.2
|
42
|
+
BytesConverter::convert "12.3 bk" # --> 0.0 (b is not recognized)
|
43
|
+
BytesConverter::convert "12,3m" # --> 12897484.8
|
44
|
+
BytesConverter::convert "123" # --> 123
|
45
|
+
```
|
46
|
+
|
47
|
+
You can add new unit as a hash. Let's say you want OrangeBytes unit:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
orange = {"o" => 2}
|
51
|
+
BytesConverter::add_unit orange
|
52
|
+
```
|
53
|
+
|
54
|
+
... and remove it with:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
BytesConverter::remove_unit "o"
|
58
|
+
```
|
59
|
+
|
60
|
+
To get all available units:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
BytesConverter::get_units # --> Hash
|
64
|
+
```
|
22
65
|
|
23
66
|
## Contributing
|
24
67
|
|
data/lib/bytes_converter.rb
CHANGED