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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6ab4b8aff36a0b16d4d6f5cd49211e529d89c98
4
- data.tar.gz: fd675a23ddc96a31df110a657336d05e318b5496
3
+ metadata.gz: 8d50f34812c3018cdfb7b43ec1f03d258414275e
4
+ data.tar.gz: 7f9c07a84e06f2444eaddf00eefd80ee75568c39
5
5
  SHA512:
6
- metadata.gz: 79491b2a2319b077f0c72a4df781c6521d6f332c0b4ede9848c3c516e970667558d8663a8c561084fa5b1acbb12953ba7109eaf113640500c933540ee67d3065
7
- data.tar.gz: c8f2a12fa5c03aff44916bd53aaf102a0867a994546cf41affee7d993fac70045eb5da8e5204176a4a2db282db4369a2adfbc4381d7b76a6782e857387d99316
6
+ metadata.gz: '09ba347b293c28af353b1a652f183a9c0fee1260bce644b2c7234e416b977d309b533b08657c8deed09a4cf897d0ebffc748cfc651c96908a7520645976f87b5'
7
+ data.tar.gz: c86e051fe9d590e64098f6c22d6c5a9f4b27a0881803feaaacb500464c2f84ee27494aa64ac16d6bb9c092add7db976812b3c0d4337f61f3c60c7482d2dae538
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
+ gemspec
3
+
4
+ # gem 'byteme', git: 'https://github.com/droctothorpe/byteme.git'
2
5
 
3
- gem 'byteme', git: 'https://github.com/droctothorpe/byteme.git'
4
6
 
5
- # Specify your gem's dependencies in byteme.gemspec
6
- gemspec
data/README.md CHANGED
@@ -4,8 +4,6 @@ Can you just Google it? Yes. Is leaving terminal for newbs? Maybe.
4
4
 
5
5
  ![image](gingerbread.jpg)
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
- Note: if no input format is specified, ByteMe assumes that the input format is Bytes.
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
- Optional `-r / --round` flag to print output as rounded floats instead of in scientific notation.
17
+ Input/Output format can be any value from the left-hand column:
19
18
 
20
- Input/Output format can be:
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 | bits |
31
- | kb | kilobits |
32
- | mb | megabits |
33
- | gb | gigabits |
34
- | tb | terabits |
35
- | pb | petabits |
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
- ``` ./bin/byteme 1000
47
- +-----------+----------+
48
- | Type | Value |
49
- +-----------+----------+
50
- | Bytes | 1000.0 |
51
- | Kilobytes | 1.0 |
52
- | Megabytes | 0.001 |
53
- | Gigabytes | 1.0e-06 |
54
- | Terabytes | 1.0e-09 |
55
- | Petabytes | 1.0e-12 |
56
- | bits | 8000.0 |
57
- | kilobits | 0.125 |
58
- | megabits | 0.000125 |
59
- | gigabits | 1.25e-07 |
60
- | terabits | 1.25e-10 |
61
- | petabits | 1.25e-13 |
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!
@@ -1,42 +1,50 @@
1
1
  module Convert
2
- def self.convert(input, input_format)
3
- formulas = {
4
- B: [1, 'Bytes'],
5
- KB: [10**3, 'Kilobytes'],
6
- MB: [10**6, 'Megabytes'],
7
- GB: [10**9, 'Gigabytes'],
8
- TB: [10**12, 'Terabytes'],
9
- PB: [10**15, 'Petabytes'],
10
- b: [0.125, 'bits'],
11
- kb: [8*10**3, 'kilobits'],
12
- mb: [8*10**6, 'megabits'],
13
- gb: [8*10**9, 'gigabits'],
14
- tb: [8*10**12, 'terabits'],
15
- pb: [8*10**15, 'petabits']
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 !formulas.keys.include?(input_format.to_sym)
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
- formulas.keys.each do |key|
27
- numerator = formulas[input_format.to_sym][0]
28
- raw_value = input.to_f * numerator / formulas[key.to_sym][0]
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 = formulas[key.to_sym][1]
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
@@ -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
- Usage: <input value> <input format>
4
- Optional -r / --round flag to print output as rounded floats instead of in scientific notation.
5
- Input/Output format can be:
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
- B: Bytes
8
- KB: Kilobytes
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
- Examples:
21
- $ byteme 1000
22
- $ byteme 1000 GB
23
- $ byteme 1000 kb -r
24
- HEREDOC
28
+ Examples:
29
+ $ byteme 1000
30
+ $ byteme 1000 GB
31
+ $ byteme 1000 kb -r
32
+ HEREDOC
25
33
  end
@@ -1,3 +1,3 @@
1
1
  module ByteMe
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
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.5
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.