blackbox 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/doc/BB.html CHANGED
@@ -104,7 +104,7 @@
104
104
  <dt id="VERSION-constant" class="">VERSION =
105
105
 
106
106
  </dt>
107
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>1.1.1</span><span class='tstring_end'>&quot;</span></span></pre></dd>
107
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>1.1.2</span><span class='tstring_end'>&quot;</span></span></pre></dd>
108
108
 
109
109
  </dl>
110
110
 
@@ -120,7 +120,7 @@
120
120
  </div>
121
121
 
122
122
  <div id="footer">
123
- Generated on Sun Nov 22 18:31:14 2015 by
123
+ Generated on Sun Nov 22 18:39:44 2015 by
124
124
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
125
125
  0.8.5.2 (ruby-2.2.2).
126
126
  </div>
data/doc/BB/Crypto.html CHANGED
@@ -1136,7 +1136,7 @@
1136
1136
  </div>
1137
1137
 
1138
1138
  <div id="footer">
1139
- Generated on Sun Nov 22 18:31:14 2015 by
1139
+ Generated on Sun Nov 22 18:39:45 2015 by
1140
1140
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1141
1141
  0.8.5.2 (ruby-2.2.2).
1142
1142
  </div>
data/doc/BB/Hash.html CHANGED
@@ -432,7 +432,7 @@ BB::Hash.flatten_prop_style(input)
432
432
  </div>
433
433
 
434
434
  <div id="footer">
435
- Generated on Sun Nov 22 18:31:14 2015 by
435
+ Generated on Sun Nov 22 18:39:44 2015 by
436
436
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
437
437
  0.8.5.2 (ruby-2.2.2).
438
438
  </div>
data/doc/BB/Number.html CHANGED
@@ -141,7 +141,7 @@
141
141
 
142
142
  <span class="summary_desc"><div class='inline'>
143
143
  <p>Formats the bytes in <code>size</code> into a more understandable
144
- representation (e.g., giving it 1500 yields 1.5 KB).</p>
144
+ representation (e.g., giving it 1500 yields 1.5k).</p>
145
145
  </div></span>
146
146
 
147
147
  </li>
@@ -219,7 +219,7 @@ representation (e.g., giving it 1500 yields 1.5 KB).</p>
219
219
  <div class="discussion">
220
220
 
221
221
  <p>Formats the bytes in <code>size</code> into a more understandable
222
- representation (e.g., giving it 1500 yields 1.5 KB). This method is useful
222
+ representation (e.g., giving it 1500 yields 1.5k). This method is useful
223
223
  for reporting file sizes to users. This method returns nil if
224
224
  <code>size</code> cannot be converted into a number. You can customize the
225
225
  format in the <code>options</code> hash.</p>
@@ -233,15 +233,15 @@ format in the <code>options</code> hash.</p>
233
233
  <p class="tag_title">Examples:</p>
234
234
 
235
235
 
236
- <pre class="example code"><code><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>123</span><span class='rparen'>)</span> <span class='comment'># =&gt; 123 Bytes
237
- </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.2 KB
238
- </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>12345</span><span class='rparen'>)</span> <span class='comment'># =&gt; 12.1 KB
239
- </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.2 MB
240
- </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567890</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.1 GB
241
- </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567890123</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.1 TB
242
- </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567</span><span class='comma'>,</span> <span class='symbol'>:precision</span> <span class='op'>=&gt;</span> <span class='int'>2</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.18 MB
243
- </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>483989</span><span class='comma'>,</span> <span class='symbol'>:precision</span> <span class='op'>=&gt;</span> <span class='int'>0</span><span class='rparen'>)</span> <span class='comment'># =&gt; 473 KB
244
- </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567</span><span class='comma'>,</span> <span class='symbol'>:precision</span> <span class='op'>=&gt;</span> <span class='int'>2</span><span class='comma'>,</span> <span class='symbol'>:separator</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>,</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'># =&gt; 1,18 MB</span></code></pre>
236
+ <pre class="example code"><code><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>123</span><span class='rparen'>)</span> <span class='comment'># =&gt; 123
237
+ </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.2k
238
+ </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>12345</span><span class='rparen'>)</span> <span class='comment'># =&gt; 12.1k
239
+ </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.2M
240
+ </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567890</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.1G
241
+ </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567890123</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.1T
242
+ </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567</span><span class='comma'>,</span> <span class='symbol'>:precision</span> <span class='op'>=&gt;</span> <span class='int'>2</span><span class='rparen'>)</span> <span class='comment'># =&gt; 1.18M
243
+ </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>483989</span><span class='comma'>,</span> <span class='symbol'>:precision</span> <span class='op'>=&gt;</span> <span class='int'>0</span><span class='rparen'>)</span> <span class='comment'># =&gt; 473k
244
+ </span><span class='id identifier rubyid_to_human_size'>to_human_size</span><span class='lparen'>(</span><span class='int'>1234567</span><span class='comma'>,</span> <span class='symbol'>:precision</span> <span class='op'>=&gt;</span> <span class='int'>2</span><span class='comma'>,</span> <span class='symbol'>:separator</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>,</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'># =&gt; 1,18M</span></code></pre>
245
245
 
246
246
  </div>
247
247
 
@@ -369,7 +369,7 @@ format in the <code>options</code> hash.</p>
369
369
  <span class="default">
370
370
 
371
371
  &mdash; default:
372
- <tt>&quot;%n %u&quot;</tt>
372
+ <tt>&quot;%n%u&quot;</tt>
373
373
 
374
374
  </span>
375
375
 
@@ -444,8 +444,7 @@ format in the <code>options</code> hash.</p>
444
444
  76
445
445
  77
446
446
  78
447
- 79
448
- 80</pre>
447
+ 79</pre>
449
448
  </td>
450
449
  <td>
451
450
  <pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 45</span>
@@ -462,12 +461,11 @@ format in the <code>options</code> hash.</p>
462
461
  <span class='id identifier rubyid_storage_units_format'>storage_units_format</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:format</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>%n%u</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
463
462
 
464
463
  <span class='kw'>if</span> <span class='id identifier rubyid_number'>number</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='op'>&lt;</span> <span class='id identifier rubyid_kilo'>kilo</span>
465
- <span class='comment'>#unit = I18n.translate(:&#39;number.human.storage_units.units.byte&#39;, :locale =&gt; options[:locale], :count =&gt; number.to_i, :raise =&gt; true)
466
- </span> <span class='id identifier rubyid_storage_units_format'>storage_units_format</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>%n</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='id identifier rubyid_number'>number</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>%u</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
464
+ <span class='id identifier rubyid_storage_units_format'>storage_units_format</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>%n</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='id identifier rubyid_number'>number</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>%u</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
467
465
  <span class='kw'>else</span>
468
466
  <span class='id identifier rubyid_max_exp'>max_exp</span> <span class='op'>=</span> <span class='const'>STORAGE_UNITS</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>-</span> <span class='int'>1</span>
469
467
  <span class='id identifier rubyid_number'>number</span> <span class='op'>=</span> <span class='const'>Float</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='rparen'>)</span>
470
- <span class='id identifier rubyid_exponent'>exponent</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='const'>Math</span><span class='period'>.</span><span class='id identifier rubyid_log'>log</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='rparen'>)</span> <span class='op'>/</span> <span class='const'>Math</span><span class='period'>.</span><span class='id identifier rubyid_log'>log</span><span class='lparen'>(</span><span class='id identifier rubyid_kilo'>kilo</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='comment'># Convert to base 1024
468
+ <span class='id identifier rubyid_exponent'>exponent</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='const'>Math</span><span class='period'>.</span><span class='id identifier rubyid_log'>log</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='rparen'>)</span> <span class='op'>/</span> <span class='const'>Math</span><span class='period'>.</span><span class='id identifier rubyid_log'>log</span><span class='lparen'>(</span><span class='id identifier rubyid_kilo'>kilo</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='comment'># Convert to base
471
469
  </span> <span class='id identifier rubyid_exponent'>exponent</span> <span class='op'>=</span> <span class='id identifier rubyid_max_exp'>max_exp</span> <span class='kw'>if</span> <span class='id identifier rubyid_exponent'>exponent</span> <span class='op'>&gt;</span> <span class='id identifier rubyid_max_exp'>max_exp</span> <span class='comment'># we need this to avoid overflow for the highest unit
472
470
  </span> <span class='id identifier rubyid_number'>number</span> <span class='op'>/=</span> <span class='id identifier rubyid_kilo'>kilo</span> <span class='op'>**</span> <span class='id identifier rubyid_exponent'>exponent</span>
473
471
 
@@ -642,6 +640,7 @@ format in the <code>options</code> hash.</p>
642
640
  <pre class="lines">
643
641
 
644
642
 
643
+ 148
645
644
  149
646
645
  150
647
646
  151
@@ -654,11 +653,10 @@ format in the <code>options</code> hash.</p>
654
653
  158
655
654
  159
656
655
  160
657
- 161
658
- 162</pre>
656
+ 161</pre>
659
657
  </td>
660
658
  <td>
661
- <pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 149</span>
659
+ <pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 148</span>
662
660
 
663
661
  <span class='kw'>def</span> <span class='id identifier rubyid_with_delimiter'>with_delimiter</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
664
662
  <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='const'>BB</span><span class='op'>::</span><span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
@@ -846,6 +844,7 @@ customize the format in the <code>options</code> hash.</p>
846
844
  <pre class="lines">
847
845
 
848
846
 
847
+ 107
849
848
  108
850
849
  109
851
850
  110
@@ -860,11 +859,10 @@ customize the format in the <code>options</code> hash.</p>
860
859
  119
861
860
  120
862
861
  121
863
- 122
864
- 123</pre>
862
+ 122</pre>
865
863
  </td>
866
864
  <td>
867
- <pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 108</span>
865
+ <pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 107</span>
868
866
 
869
867
  <span class='kw'>def</span> <span class='id identifier rubyid_with_precision'>with_precision</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
870
868
  <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='const'>BB</span><span class='op'>::</span><span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
@@ -892,7 +890,7 @@ customize the format in the <code>options</code> hash.</p>
892
890
  </div>
893
891
 
894
892
  <div id="footer">
895
- Generated on Sun Nov 22 18:31:14 2015 by
893
+ Generated on Sun Nov 22 18:39:44 2015 by
896
894
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
897
895
  0.8.5.2 (ruby-2.2.2).
898
896
  </div>
data/doc/BB/String.html CHANGED
@@ -231,7 +231,7 @@
231
231
  </div>
232
232
 
233
233
  <div id="footer">
234
- Generated on Sun Nov 22 18:31:14 2015 by
234
+ Generated on Sun Nov 22 18:39:44 2015 by
235
235
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
236
236
  0.8.5.2 (ruby-2.2.2).
237
237
  </div>
data/doc/_index.html CHANGED
@@ -161,7 +161,7 @@
161
161
  </div>
162
162
 
163
163
  <div id="footer">
164
- Generated on Sun Nov 22 18:31:14 2015 by
164
+ Generated on Sun Nov 22 18:39:44 2015 by
165
165
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
166
166
  0.8.5.2 (ruby-2.2.2).
167
167
  </div>
data/doc/file.README.html CHANGED
@@ -95,7 +95,7 @@ BB::String.strip_ansi( ... )
95
95
  </div></div>
96
96
 
97
97
  <div id="footer">
98
- Generated on Sun Nov 22 18:31:14 2015 by
98
+ Generated on Sun Nov 22 18:39:44 2015 by
99
99
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
100
100
  0.8.5.2 (ruby-2.2.2).
101
101
  </div>
data/doc/index.html CHANGED
@@ -95,7 +95,7 @@ BB::String.strip_ansi( ... )
95
95
  </div></div>
96
96
 
97
97
  <div id="footer">
98
- Generated on Sun Nov 22 18:31:14 2015 by
98
+ Generated on Sun Nov 22 18:39:44 2015 by
99
99
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
100
100
  0.8.5.2 (ruby-2.2.2).
101
101
  </div>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Sun Nov 22 18:31:14 2015 by
106
+ Generated on Sun Nov 22 18:39:44 2015 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.5.2 (ruby-2.2.2).
109
109
  </div>
data/lib/blackbox.rb CHANGED
@@ -2,3 +2,4 @@ require "blackbox/version"
2
2
  require "blackbox/crypto"
3
3
  require "blackbox/string"
4
4
  require "blackbox/hash"
5
+ require "blackbox/number"
@@ -8,7 +8,7 @@ module BB
8
8
 
9
9
  ##
10
10
  # Formats the bytes in +size+ into a more understandable representation
11
- # (e.g., giving it 1500 yields 1.5 KB). This method is useful for
11
+ # (e.g., giving it 1500 yields 1.5k). This method is useful for
12
12
  # reporting file sizes to users. This method returns nil if
13
13
  # +size+ cannot be converted into a number. You can customize the
14
14
  # format in the +options+ hash.
@@ -26,21 +26,21 @@ module BB
26
26
  # Sets the thousands delimiter.
27
27
  # @option options [String] :kilo (1024)
28
28
  # Sets the number of bytes in a kilobyte.
29
- # @option options [String] :format ("%n %u")
29
+ # @option options [String] :format ("%n%u")
30
30
  # Sets the display format.
31
31
  #
32
32
  # @return [String] The formatted representation of bytes
33
33
  #
34
34
  # @example
35
- # to_human_size(123) # => 123 Bytes
36
- # to_human_size(1234) # => 1.2 KB
37
- # to_human_size(12345) # => 12.1 KB
38
- # to_human_size(1234567) # => 1.2 MB
39
- # to_human_size(1234567890) # => 1.1 GB
40
- # to_human_size(1234567890123) # => 1.1 TB
41
- # to_human_size(1234567, :precision => 2) # => 1.18 MB
42
- # to_human_size(483989, :precision => 0) # => 473 KB
43
- # to_human_size(1234567, :precision => 2, :separator => ',') # => 1,18 MB
35
+ # to_human_size(123) # => 123
36
+ # to_human_size(1234) # => 1.2k
37
+ # to_human_size(12345) # => 12.1k
38
+ # to_human_size(1234567) # => 1.2M
39
+ # to_human_size(1234567890) # => 1.1G
40
+ # to_human_size(1234567890123) # => 1.1T
41
+ # to_human_size(1234567, :precision => 2) # => 1.18M
42
+ # to_human_size(483989, :precision => 0) # => 473k
43
+ # to_human_size(1234567, :precision => 2, :separator => ',') # => 1,18M
44
44
  #
45
45
  def to_human_size(number, args={})
46
46
  return nil if number.nil?
@@ -54,12 +54,11 @@ module BB
54
54
  storage_units_format ||= (options[:format] || '%n%u')
55
55
 
56
56
  if number.to_i < kilo
57
- #unit = I18n.translate(:'number.human.storage_units.units.byte', :locale => options[:locale], :count => number.to_i, :raise => true)
58
57
  storage_units_format.gsub(/%n/, number.to_i.to_s).gsub(/%u/, '')
59
58
  else
60
59
  max_exp = STORAGE_UNITS.size - 1
61
60
  number = Float(number)
62
- exponent = (Math.log(number) / Math.log(kilo)).to_i # Convert to base 1024
61
+ exponent = (Math.log(number) / Math.log(kilo)).to_i # Convert to base
63
62
  exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
64
63
  number /= kilo ** exponent
65
64
 
@@ -1,3 +1,3 @@
1
1
  module BB
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moe