linux_stat 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d99cfc873aefbafccebb72accbc5d70e519ea76b2bc258a15f9a94195a83601b
4
- data.tar.gz: 70c42c719c4f4392ffdd2bc247f5b9ed8a79d064eb8e6daf6c72d35d26f8f1df
3
+ metadata.gz: f6509d9a0ed303d95d92e1d410bd2e8ee1046d0b320cdbc5a2c8230b20037614
4
+ data.tar.gz: ca02da4c022fe3dfcb0a900537cc1389a602a8d79e5f300ffe206878d737e8f2
5
5
  SHA512:
6
- metadata.gz: 0422e7abf9f8c860702d61cdb13e5b6f8506b5a4109fe523d351c62a55c777e4d9e7c506f689bae37aef68ea5afef66f0a7264e7a6cf03cf1c2322413387631f
7
- data.tar.gz: b5b13a08a59c327406bc917040349ef857c39bef27fe5e79a033865f9b9443b2385abb68d7e8e6c0d5bbfda418787d591456e81c392535254c0ae3eaee98cdde
6
+ metadata.gz: e0c2ce5029b1fb98812a18a6f5383f52b89b06fbf2bba3ed1bda29d880491cba781950ed3295e4a85b6040b8f62a68c6de390598bfd9d6cd53bd1f141e6815f3
7
+ data.tar.gz: 40b493dc6dd1c9f862ceeab1ee2c24e3493996560cc214046167907f01fca9ec262dfa54f2d237212ec2cd50f84ae2b0ae5a41be62b6017c5833dc9895235807
@@ -7,6 +7,28 @@ module LinuxStat
7
7
  # 4. kiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB
8
8
 
9
9
  module PrettifyBytes
10
+ # Kilo = Kilobyte (1000 - 1), and so on...
11
+ # 8.times { |x| puts 1000.**(x.next).to_s << '.00' }
12
+ KILO = 1000.00
13
+ MEGA = 1000000.00
14
+ GIGA = 1000000000.00
15
+ TERA = 1000000000000.00
16
+ PETA = 1000000000000000.00
17
+ EXA = 1000000000000000000.00
18
+ ZETTA = 1000000000000000000000.00
19
+ YOTTA = 1000000000000000000000000.00
20
+
21
+ # Binary suffixes
22
+ # 8.times { |x| puts 1024.**(x.next).to_s << '.00' }
23
+ KIBI = 1024.00
24
+ MEBI = 1048576.00
25
+ GIBI = 1073741824.00
26
+ TEBI = 1099511627776.00
27
+ PEBI = 1125899906842624.00
28
+ EXBI = 1152921504606846976.00
29
+ ZEBI = 1180591620717411303424.00
30
+ YOBI = 1208925819614629174706176.00
31
+
10
32
  class << self
11
33
  ##
12
34
  # Converts a number to decimal byte units and outputs with the metric prefix
@@ -24,12 +46,33 @@ module LinuxStat
24
46
  #
25
47
  # => "1.07 gigabytes"
26
48
  def convert_decimal(n, precision: 2)
27
- @@d_units ||= %W(#{''} kilo mega giga tera peta exa zetta)
28
- .map.with_index { |x, i| [x, 1000.**(i + 1)] }
29
- unit = @@d_units.find { |x| n < x[1] } || ['yotta'.freeze, 10 ** 27]
30
-
31
- converted = n.fdiv(unit[1] / 1000).round(2)
32
- "#{pad_left(converted, precision)} #{unit[0]}byte#{?s.freeze if converted != 1}"
49
+ if n < KILO
50
+ "#{"%.#{precision}f" % n} byte#{?s.freeze if n != 1}"
51
+ elsif n < MEGA
52
+ n /= KILO
53
+ "#{"%.#{precision}f" % n} kilobyte#{?s.freeze if n != 1}"
54
+ elsif n < GIGA
55
+ n /= MEGA
56
+ "#{"%.#{precision}f" % n} megabyte#{?s.freeze if n != 1}"
57
+ elsif n < TERA
58
+ n /= GIGA
59
+ "#{"%.#{precision}f" % n} gigabyte#{?s.freeze if n != 1}"
60
+ elsif n < PETA
61
+ n /= TERA
62
+ "#{"%.#{precision}f" % n} terabyte#{?s.freeze if n != 1}"
63
+ elsif n < EXA
64
+ n /= PETA
65
+ "#{"%.#{precision}f" % n} petabyte#{?s.freeze if n != 1}"
66
+ elsif n < ZETTA
67
+ n /= EXA
68
+ "#{"%.#{precision}f" % n} exabyte#{?s.freeze if n != 1}"
69
+ elsif n < YOTTA
70
+ n /= ZETTA
71
+ "#{"%.#{precision}f" % n} zettabyte#{?s.freeze if n != 1}"
72
+ else
73
+ n /= YOTTA
74
+ "#{"%.#{precision}f" % n} yottabyte#{?s.freeze if n != 1}"
75
+ end
33
76
  end
34
77
 
35
78
  # Converts a number to binary byte units and outputs with the IEC prefix
@@ -47,12 +90,33 @@ module LinuxStat
47
90
  #
48
91
  # => "1.0 gibibyte"
49
92
  def convert_binary(n, precision: 2)
50
- @@b_units ||= %W(#{''} kibi mebi gibi tebi pebi exbi zebi)
51
- .map.with_index { |x, i| [x, 1024.**(i + 1)] }
52
- unit = @@b_units.find { |x| n < x[1] } || ['yobi'.freeze, 10 ** 27]
53
-
54
- converted = n.fdiv(unit[1] / 1024).round(2)
55
- "#{pad_left(converted, precision)} #{unit[0]}byte#{?s.freeze if converted != 1}"
93
+ if n < KIBI
94
+ "#{"%.#{precision}f" % n} byte#{?s.freeze if n != 1}"
95
+ elsif n < MEBI
96
+ n /= KIBI
97
+ "#{"%.#{precision}f" % n} kibibyte#{?s.freeze if n != 1}"
98
+ elsif n < GIBI
99
+ n /= MEBI
100
+ "#{"%.#{precision}f" % n} mebibyte#{?s.freeze if n != 1}"
101
+ elsif n < TEBI
102
+ n /= GIBI
103
+ "#{"%.#{precision}f" % n} gibibyte#{?s.freeze if n != 1}"
104
+ elsif n < PEBI
105
+ n /= TEBI
106
+ "#{"%.#{precision}f" % n} tebibyte#{?s.freeze if n != 1}"
107
+ elsif n < EXBI
108
+ n /= PEBI
109
+ "#{"%.#{precision}f" % n} pebibyte#{?s.freeze if n != 1}"
110
+ elsif n < ZEBI
111
+ n /= EXBI
112
+ "#{"%.#{precision}f" % n} exbiyte#{?s.freeze if n != 1}"
113
+ elsif n < YOBI
114
+ n /= ZEBI
115
+ "#{"%.#{precision}f" % n} zebibyte#{?s.freeze if n != 1}"
116
+ else
117
+ n /= YOBI
118
+ "#{"%.#{precision}f" % n} yobibyte#{?s.freeze if n != 1}"
119
+ end
56
120
  end
57
121
 
58
122
  # Converts a number to decimal byte units
@@ -70,12 +134,33 @@ module LinuxStat
70
134
  #
71
135
  # => "1.07 GB"
72
136
  def convert_short_decimal(n, precision: 2)
73
- @@sd_units ||= %W(#{''} k M G T P E Z)
74
- .map.with_index { |x, i| [x, 1000.**(i + 1)] }
75
- unit = @@sd_units.find { |x| n < x[1] } || [?Y.freeze, 10 ** 27]
76
-
77
- converted = n.fdiv(unit[1] / 1000).round(2)
78
- "#{pad_left(converted, precision)} #{unit[0]}B"
137
+ if n < KILO
138
+ "#{"%.#{precision}f" % n} B"
139
+ elsif n < MEGA
140
+ n /= KILO
141
+ "#{"%.#{precision}f" % n} kB"
142
+ elsif n < GIGA
143
+ n /= MEGA
144
+ "#{"%.#{precision}f" % n} MB"
145
+ elsif n < TERA
146
+ n /= GIGA
147
+ "#{"%.#{precision}f" % n} GB"
148
+ elsif n < PETA
149
+ n /= TERA
150
+ "#{"%.#{precision}f" % n} TB"
151
+ elsif n < EXA
152
+ n /= PETA
153
+ "#{"%.#{precision}f" % n} PB"
154
+ elsif n < ZETTA
155
+ n /= EXA
156
+ "#{"%.#{precision}f" % n} EB"
157
+ elsif n < YOTTA
158
+ n /= ZETTA
159
+ "#{"%.#{precision}f" % n} ZB"
160
+ else
161
+ n /= YOTTA
162
+ "#{"%.#{precision}f" % n} YB"
163
+ end
79
164
  end
80
165
 
81
166
  ##
@@ -95,19 +180,33 @@ module LinuxStat
95
180
  #
96
181
  # => "1.0 GiB"
97
182
  def convert_short_binary(n, precision: 2)
98
- return "#{pad_left(n, precision)} B" if n < 1024
99
-
100
- @@sb_units ||= %W(#{''} K M G T P E Z)
101
- .map.with_index { |x, i| [x, 1024.**(i + 1)] }
102
- unit = @@sb_units.find { |x| n < x[1] } || [?Y.freeze, 1024 ** 9]
103
-
104
- converted = n.fdiv(unit[1] / 1024).round(2)
105
- "#{pad_left(converted, precision)} #{unit[0]}iB"
106
- end
107
-
108
- private
109
- def pad_left(n, mantissa_length = 2)
110
- sprintf("%.#{mantissa_length}f".freeze, n)
183
+ if n < KIBI
184
+ "#{"%.#{precision}f" % n} B"
185
+ elsif n < MEBI
186
+ n /= KIBI
187
+ "#{"%.#{precision}f" % n} KiB"
188
+ elsif n < GIBI
189
+ n /= MEBI
190
+ "#{"%.#{precision}f" % n} MiB"
191
+ elsif n < TEBI
192
+ n /= GIBI
193
+ "#{"%.#{precision}f" % n} GiB"
194
+ elsif n < PEBI
195
+ n /= TEBI
196
+ "#{"%.#{precision}f" % n} TiB"
197
+ elsif n < EXBI
198
+ n /= PEBI
199
+ "#{"%.#{precision}f" % n} PiB"
200
+ elsif n < ZEBI
201
+ n /= EXBI
202
+ "#{"%.#{precision}f" % n} EiB"
203
+ elsif n < YOBI
204
+ n /= ZEBI
205
+ "#{"%.#{precision}f" % n} ZiB"
206
+ else
207
+ n /= YOBI
208
+ "#{"%.#{precision}f" % n} YiB"
209
+ end
111
210
  end
112
211
  end
113
212
  end
@@ -1,3 +1,3 @@
1
1
  module LinuxStat
2
- VERSION ||= "2.2.2"
2
+ VERSION = "2.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-09 00:00:00.000000000 Z
11
+ date: 2021-05-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux only, efficient linux system utilization reporting and system monitoring
14
14
  gem
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.2.13
88
+ rubygems_version: 3.2.15
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Efficient linux system reporting gem