byteme 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/README.md +41 -30
- data/lib/byteme/convert.rb +30 -22
- data/lib/byteme/usage.rb +28 -20
- data/lib/byteme/version.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d50f34812c3018cdfb7b43ec1f03d258414275e
|
4
|
+
data.tar.gz: 7f9c07a84e06f2444eaddf00eefd80ee75568c39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09ba347b293c28af353b1a652f183a9c0fee1260bce644b2c7234e416b977d309b533b08657c8deed09a4cf897d0ebffc748cfc651c96908a7520645976f87b5'
|
7
|
+
data.tar.gz: c86e051fe9d590e64098f6c22d6c5a9f4b27a0881803feaaacb500464c2f84ee27494aa64ac16d6bb9c092add7db976812b3c0d4337f61f3c60c7482d2dae538
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,8 +4,6 @@ Can you just Google it? Yes. Is leaving terminal for newbs? Maybe.
|
|
4
4
|
|
5
5
|

|
6
6
|
|
7
|
-
|
8
|
-
|
9
7
|
## Installation
|
10
8
|
|
11
9
|
`gem install byteme`
|
@@ -13,13 +11,12 @@ Can you just Google it? Yes. Is leaving terminal for newbs? Maybe.
|
|
13
11
|
## Usage
|
14
12
|
`byteme <input value> <input format>`
|
15
13
|
|
16
|
-
|
14
|
+
If no input format is specified, Bytes is assumed.
|
15
|
+
You can pass the `-r` or `--round` flag to print output as rounded floats instead of in scientific notation.
|
17
16
|
|
18
|
-
|
17
|
+
Input/Output format can be any value from the left-hand column:
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
| Command Argument | Corresponds To |
|
19
|
+
| Argument | Corresponds To |
|
23
20
|
| ---------------- | -------------- |
|
24
21
|
| B | Bytes |
|
25
22
|
| KB | Kilobytes |
|
@@ -27,12 +24,17 @@ Input/Output format can be:
|
|
27
24
|
| GB | Gigabytes |
|
28
25
|
| TB | Terabytes |
|
29
26
|
| PB | Petabytes |
|
30
|
-
| b |
|
31
|
-
| kb |
|
32
|
-
| mb |
|
33
|
-
| gb |
|
34
|
-
| tb |
|
35
|
-
| pb |
|
27
|
+
| b | Bits |
|
28
|
+
| kb | Kilobits |
|
29
|
+
| mb | Megabits |
|
30
|
+
| gb | Gigabits |
|
31
|
+
| tb | Terabits |
|
32
|
+
| pb | Petabits |
|
33
|
+
| KiB | Kibibytes |
|
34
|
+
| MiB | Mebibytes |
|
35
|
+
| GiB | Gibibytes |
|
36
|
+
| TiB | Tebibytes |
|
37
|
+
| PiB | Pebibytes |
|
36
38
|
|
37
39
|
## Examples:
|
38
40
|
`$ byteme 1000 `
|
@@ -43,23 +45,32 @@ Input/Output format can be:
|
|
43
45
|
|
44
46
|
## Example output:
|
45
47
|
|
46
|
-
```
|
47
|
-
|
48
|
-
| Type | Value
|
49
|
-
|
50
|
-
| Bytes | 1000
|
51
|
-
| Kilobytes | 1
|
52
|
-
| Megabytes | 0.001
|
53
|
-
| Gigabytes | 1.0e-06
|
54
|
-
| Terabytes | 1.0e-09
|
55
|
-
| Petabytes | 1.0e-12
|
56
|
-
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
48
|
+
```byteme 1000
|
49
|
+
+-----------+-----------------------+
|
50
|
+
| Type | Value |
|
51
|
+
+-----------+-----------------------+
|
52
|
+
| Bytes | 1000 |
|
53
|
+
| Kilobytes | 1 |
|
54
|
+
| Megabytes | 0.001 |
|
55
|
+
| Gigabytes | 1.0e-06 |
|
56
|
+
| Terabytes | 1.0e-09 |
|
57
|
+
| Petabytes | 1.0e-12 |
|
58
|
+
+-----------+-----------------------+
|
59
|
+
| Bits | 8000 |
|
60
|
+
| Kilobits | 0.125 |
|
61
|
+
| Megabits | 0.000125 |
|
62
|
+
| Gigabits | 1.25e-07 |
|
63
|
+
| Terabits | 1.25e-1 |
|
64
|
+
| Petabits | 1.25e-13 |
|
65
|
+
+-----------+-----------------------+
|
66
|
+
| Kibibytes | 0.9765625 |
|
67
|
+
| Mebibytes | 0.00095367431640625 |
|
68
|
+
| Gibibytes | 9.313225746154785e-07 |
|
69
|
+
| Tebibytes | 9.094947017729282e-1 |
|
70
|
+
| Pebibytes | 8.881784197001252e-13 |
|
71
|
+
+-----------+-----------------------+
|
63
72
|
```
|
64
73
|
|
74
|
+
Link to RubyGems: https://rubygems.org/gems/byteme
|
75
|
+
|
65
76
|
PRs are welcome!
|
data/lib/byteme/convert.rb
CHANGED
@@ -1,42 +1,50 @@
|
|
1
1
|
module Convert
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
2
|
+
FORMULAS = {
|
3
|
+
B: [1, 'Bytes'],
|
4
|
+
KB: [10**3, 'Kilobytes'],
|
5
|
+
MB: [10**6, 'Megabytes'],
|
6
|
+
GB: [10**9, 'Gigabytes'],
|
7
|
+
TB: [10**12, 'Terabytes'],
|
8
|
+
PB: [10**15, 'Petabytes'],
|
9
|
+
b: [0.125, 'Bits'],
|
10
|
+
kb: [8*10**3, 'Kilobits'],
|
11
|
+
mb: [8*10**6, 'Megabits'],
|
12
|
+
gb: [8*10**9, 'Gigabits'],
|
13
|
+
tb: [8*10**12, 'Terabits'],
|
14
|
+
pb: [8*10**15, 'Petabits'],
|
15
|
+
KiB: [1024, 'Kibibytes'],
|
16
|
+
MiB: [1024**2, 'Mebibytes'],
|
17
|
+
GiB: [1024**3, 'Gibibytes'],
|
18
|
+
TiB: [1024**4, 'Tebibytes'],
|
19
|
+
PiB: [1024**5, 'Pebibytes']
|
20
|
+
}
|
17
21
|
|
22
|
+
def self.convert(input, input_format)
|
18
23
|
# Sanitize input
|
19
|
-
if !
|
24
|
+
if !FORMULAS.keys.include?(input_format.to_sym)
|
20
25
|
puts "Error: input format (#{input_format}) is incorrect."
|
21
26
|
puts @usage
|
22
27
|
return
|
23
28
|
end
|
24
29
|
|
25
30
|
rows = []
|
26
|
-
|
27
|
-
numerator =
|
28
|
-
raw_value = input.to_f * numerator /
|
31
|
+
FORMULAS.keys.each do |key|
|
32
|
+
numerator = FORMULAS[input_format.to_sym][0]
|
33
|
+
raw_value = input.to_f * numerator / FORMULAS[key.to_sym][0]
|
29
34
|
if Parse.get
|
30
35
|
output = ( "%.5f" % raw_value ).sub(/\.?0*$/, '')
|
31
36
|
else
|
32
|
-
output = raw_value
|
37
|
+
output = raw_value.to_s.sub(/\.?0*$/, '')
|
33
38
|
end
|
34
|
-
output_format =
|
39
|
+
output_format = FORMULAS[key.to_sym][1]
|
35
40
|
rows.push([output_format, output])
|
41
|
+
# Add seperator between output categories.
|
42
|
+
if ([key.to_s] & ['PB', 'pb']).any?
|
43
|
+
rows << :separator
|
44
|
+
end
|
36
45
|
end
|
37
46
|
|
38
47
|
table = Terminal::Table.new :headings => ['Type', 'Value'], :rows => rows
|
39
|
-
# table.style = {:all_separators => true}
|
40
48
|
puts table
|
41
49
|
end
|
42
50
|
end
|
data/lib/byteme/usage.rb
CHANGED
@@ -1,25 +1,33 @@
|
|
1
|
+
require 'byteme/convert'
|
2
|
+
require 'terminal-table'
|
3
|
+
|
1
4
|
module Usage
|
5
|
+
rows = []
|
6
|
+
Convert::FORMULAS.each do |key, value|
|
7
|
+
rows.push([key, value[1]])
|
8
|
+
end
|
9
|
+
table = Terminal::Table.new :rows => rows
|
10
|
+
|
11
|
+
# Options String
|
12
|
+
# options_string = ""
|
13
|
+
# Convert::FORMULAS.each do |key, value|
|
14
|
+
# options_string << "#{key}: #{value[1]}\n"
|
15
|
+
# end
|
16
|
+
|
2
17
|
USAGE = <<-HEREDOC
|
3
|
-
|
4
|
-
|
5
|
-
|
18
|
+
Usage:
|
19
|
+
$ byteme <input value> <optional input format>
|
20
|
+
|
21
|
+
If no input format is specified, Bytes is assumed.
|
22
|
+
|
23
|
+
You can pass the -r or --round flag to print output as rounded floats instead of in scientific notation.
|
6
24
|
|
7
|
-
|
8
|
-
|
9
|
-
MB: Megabytes
|
10
|
-
GB: Gigabytes
|
11
|
-
TB: Terabytes
|
12
|
-
PB: Petabytes
|
13
|
-
b: bits
|
14
|
-
kb: kilobits
|
15
|
-
mb: megabits
|
16
|
-
gb: gigabits
|
17
|
-
tb: terabits
|
18
|
-
pb: petabits
|
25
|
+
Input/Output format can be any value from the left-hand column:
|
26
|
+
#{table}
|
19
27
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
Examples:
|
29
|
+
$ byteme 1000
|
30
|
+
$ byteme 1000 GB
|
31
|
+
$ byteme 1000 kb -r
|
32
|
+
HEREDOC
|
25
33
|
end
|
data/lib/byteme/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: byteme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Perlman
|
@@ -15,6 +15,9 @@ dependencies:
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 1.8.0
|
20
23
|
type: :runtime
|
@@ -22,6 +25,9 @@ dependencies:
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.8'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 1.8.0
|
27
33
|
description: A simple CLI that converts between bytes, kilobytes, megabytes, etc.
|