blackbox 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,901 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Module: BB::Number
8
+
9
+ &mdash; Documentation by YARD 0.8.5.2
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '../';
20
+ framesUrl = "../frames.html#!" + escape(window.location.href);
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="../_index.html">Index (N)</a> &raquo;
35
+ <span class='title'><span class='object_link'><a href="../BB.html" title="BB (module)">BB</a></span></span>
36
+ &raquo;
37
+ <span class="title">Number</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="../class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="../method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="../file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Module: BB::Number
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ <dt class="r1 last">Defined in:</dt>
82
+ <dd class="r1 last">lib/blackbox/number.rb</dd>
83
+
84
+ </dl>
85
+ <div class="clear"></div>
86
+
87
+ <h2>Overview</h2><div class="docstring">
88
+ <div class="discussion">
89
+
90
+ <p>String utilities.</p>
91
+
92
+
93
+ </div>
94
+ </div>
95
+ <div class="tags">
96
+
97
+
98
+ </div>
99
+ <h2>Constant Summary</h2>
100
+
101
+ <dl class="constants">
102
+
103
+ <dt id="STORAGE_UNITS-constant" class="">STORAGE_UNITS =
104
+
105
+ </dt>
106
+ <dd><pre class="code"><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>byte</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>k</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>M</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>G</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>T</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>P</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>E</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Z</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Y</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
107
+
108
+ </dl>
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ <h2>
119
+ Class Method Summary
120
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
121
+ </h2>
122
+
123
+ <ul class="summary">
124
+
125
+ <li class="public ">
126
+ <span class="summary_signature">
127
+
128
+ <a href="#to_human_size-class_method" title="to_human_size (class method)">+ (String) <strong>to_human_size</strong>(number, options = {}) </a>
129
+
130
+
131
+
132
+ </span>
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+ <span class="summary_desc"><div class='inline'>
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>
145
+ </div></span>
146
+
147
+ </li>
148
+
149
+
150
+ <li class="public ">
151
+ <span class="summary_signature">
152
+
153
+ <a href="#with_delimiter-class_method" title="with_delimiter (class method)">+ (String) <strong>with_delimiter</strong>(number, options = {}) </a>
154
+
155
+
156
+
157
+ </span>
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+ <span class="summary_desc"><div class='inline'>
168
+ <p>Formats a <code>number</code> with grouped thousands using
169
+ <code>delimiter</code> (e.g., 12,324).</p>
170
+ </div></span>
171
+
172
+ </li>
173
+
174
+
175
+ <li class="public ">
176
+ <span class="summary_signature">
177
+
178
+ <a href="#with_precision-class_method" title="with_precision (class method)">+ (String) <strong>with_precision</strong>(number, options = {}) </a>
179
+
180
+
181
+
182
+ </span>
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+ <span class="summary_desc"><div class='inline'>
193
+ <p>Formats a <code>number</code> with the specified level of
194
+ <code>:precision</code> (e.g., 112.32 has a precision of 2).</p>
195
+ </div></span>
196
+
197
+ </li>
198
+
199
+
200
+ </ul>
201
+
202
+
203
+
204
+
205
+ <div id="class_method_details" class="method_details_list">
206
+ <h2>Class Method Details</h2>
207
+
208
+
209
+ <div class="method_details first">
210
+ <h3 class="signature first" id="to_human_size-class_method">
211
+
212
+ + (<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>) <strong>to_human_size</strong>(number, options = {})
213
+
214
+
215
+
216
+
217
+
218
+ </h3><div class="docstring">
219
+ <div class="discussion">
220
+
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
223
+ for reporting file sizes to users. This method returns nil if
224
+ <code>size</code> cannot be converted into a number. You can customize the
225
+ format in the <code>options</code> hash.</p>
226
+
227
+
228
+ </div>
229
+ </div>
230
+ <div class="tags">
231
+
232
+ <div class="examples">
233
+ <p class="tag_title">Examples:</p>
234
+
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>
245
+
246
+ </div>
247
+
248
+ <div class="docstring">
249
+ <div class="discussion">
250
+
251
+
252
+ </div>
253
+ </div>
254
+ <div class="tags">
255
+ <p class="tag_title">Parameters:</p>
256
+ <ul class="param">
257
+
258
+ <li>
259
+
260
+ <span class='name'>number</span>
261
+
262
+
263
+ <span class='type'>(<tt>Fixnum</tt>)</span>
264
+
265
+
266
+
267
+ &mdash;
268
+ <div class='inline'>
269
+ <p>Number value to format.</p>
270
+ </div>
271
+
272
+ </li>
273
+
274
+ <li>
275
+
276
+ <span class='name'>options</span>
277
+
278
+
279
+ <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="BB::Hash (module)">Hash</a></span></tt>)</span>
280
+
281
+
282
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
283
+
284
+
285
+ &mdash;
286
+ <div class='inline'>
287
+ <p>Options for formatter.</p>
288
+ </div>
289
+
290
+ </li>
291
+
292
+ </ul>
293
+
294
+
295
+
296
+
297
+
298
+
299
+ <p class="tag_title">Options Hash (<tt>options</tt>):</p>
300
+ <ul class="option">
301
+
302
+ <li>
303
+ <span class="name">:precision</span>
304
+ <span class="type">(<tt>Fixnum</tt>)</span>
305
+ <span class="default">
306
+
307
+ &mdash; default:
308
+ <tt>1</tt>
309
+
310
+ </span>
311
+
312
+ &mdash; <div class='inline'>
313
+ <p>Sets the level of precision.</p>
314
+ </div>
315
+
316
+ </li>
317
+
318
+ <li>
319
+ <span class="name">:separator</span>
320
+ <span class="type">(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
321
+ <span class="default">
322
+
323
+ &mdash; default:
324
+ <tt>&quot;.&quot;</tt>
325
+
326
+ </span>
327
+
328
+ &mdash; <div class='inline'>
329
+ <p>Sets the separator between the units.</p>
330
+ </div>
331
+
332
+ </li>
333
+
334
+ <li>
335
+ <span class="name">:delimiter</span>
336
+ <span class="type">(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
337
+ <span class="default">
338
+
339
+ &mdash; default:
340
+ <tt>&quot;&quot;</tt>
341
+
342
+ </span>
343
+
344
+ &mdash; <div class='inline'>
345
+ <p>Sets the thousands delimiter.</p>
346
+ </div>
347
+
348
+ </li>
349
+
350
+ <li>
351
+ <span class="name">:kilo</span>
352
+ <span class="type">(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
353
+ <span class="default">
354
+
355
+ &mdash; default:
356
+ <tt>1024</tt>
357
+
358
+ </span>
359
+
360
+ &mdash; <div class='inline'>
361
+ <p>Sets the number of bytes in a kilobyte.</p>
362
+ </div>
363
+
364
+ </li>
365
+
366
+ <li>
367
+ <span class="name">:format</span>
368
+ <span class="type">(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
369
+ <span class="default">
370
+
371
+ &mdash; default:
372
+ <tt>&quot;%n %u&quot;</tt>
373
+
374
+ </span>
375
+
376
+ &mdash; <div class='inline'>
377
+ <p>Sets the display format.</p>
378
+ </div>
379
+
380
+ </li>
381
+
382
+ </ul>
383
+
384
+
385
+
386
+ </div>
387
+
388
+ <p class="tag_title">Returns:</p>
389
+ <ul class="return">
390
+
391
+ <li>
392
+
393
+
394
+ <span class='type'>(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
395
+
396
+
397
+
398
+ &mdash;
399
+ <div class='inline'>
400
+ <p>The formatted representation of bytes</p>
401
+ </div>
402
+
403
+ </li>
404
+
405
+ </ul>
406
+
407
+ </div><table class="source_code">
408
+ <tr>
409
+ <td>
410
+ <pre class="lines">
411
+
412
+
413
+ 45
414
+ 46
415
+ 47
416
+ 48
417
+ 49
418
+ 50
419
+ 51
420
+ 52
421
+ 53
422
+ 54
423
+ 55
424
+ 56
425
+ 57
426
+ 58
427
+ 59
428
+ 60
429
+ 61
430
+ 62
431
+ 63
432
+ 64
433
+ 65
434
+ 66
435
+ 67
436
+ 68
437
+ 69
438
+ 70
439
+ 71
440
+ 72
441
+ 73
442
+ 74
443
+ 75
444
+ 76
445
+ 77
446
+ 78
447
+ 79
448
+ 80</pre>
449
+ </td>
450
+ <td>
451
+ <pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 45</span>
452
+
453
+ <span class='kw'>def</span> <span class='id identifier rubyid_to_human_size'>to_human_size</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='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
454
+ <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_number'>number</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
455
+
456
+ <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>
457
+
458
+ <span class='id identifier rubyid_precision'>precision</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:precision</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='int'>1</span><span class='rparen'>)</span>
459
+ <span class='id identifier rubyid_separator'>separator</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:separator</span><span class='rbracket'>]</span> <span class='op'>||</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>
460
+ <span class='id identifier rubyid_delimiter'>delimiter</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:delimiter</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
461
+ <span class='id identifier rubyid_kilo'>kilo</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:kilo</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='int'>1024</span><span class='rparen'>)</span>
462
+ <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
+
464
+ <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>
467
+ <span class='kw'>else</span>
468
+ <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
+ <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
471
+ </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
+ </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
+
474
+ <span class='id identifier rubyid_unit'>unit</span> <span class='op'>=</span> <span class='const'>STORAGE_UNITS</span><span class='lbracket'>[</span><span class='id identifier rubyid_exponent'>exponent</span><span class='rbracket'>]</span>
475
+
476
+ <span class='kw'>begin</span>
477
+ <span class='id identifier rubyid_escaped_separator'>escaped_separator</span> <span class='op'>=</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_escape'>escape</span><span class='lparen'>(</span><span class='id identifier rubyid_separator'>separator</span><span class='rparen'>)</span>
478
+ <span class='id identifier rubyid_formatted_number'>formatted_number</span> <span class='op'>=</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>
479
+ <span class='symbol'>:precision</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_precision'>precision</span><span class='comma'>,</span>
480
+ <span class='symbol'>:separator</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_separator'>separator</span><span class='comma'>,</span>
481
+ <span class='symbol'>:delimiter</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_delimiter'>delimiter</span>
482
+ <span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_escaped_separator'>escaped_separator</span><span class='embexpr_end'>}</span><span class='tstring_content'>)(\d*[1-9])?0+\z</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>\1\2</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_escaped_separator'>escaped_separator</span><span class='embexpr_end'>}</span><span class='tstring_content'>\z</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>
483
+ <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_formatted_number'>formatted_number</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='id identifier rubyid_unit'>unit</span><span class='rparen'>)</span>
484
+ <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
485
+ <span class='id identifier rubyid_number'>number</span>
486
+ <span class='kw'>end</span>
487
+ <span class='kw'>end</span>
488
+ <span class='kw'>end</span></pre>
489
+ </td>
490
+ </tr>
491
+ </table>
492
+ </div>
493
+
494
+ <div class="method_details ">
495
+ <h3 class="signature " id="with_delimiter-class_method">
496
+
497
+ + (<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>) <strong>with_delimiter</strong>(number, options = {})
498
+
499
+
500
+
501
+
502
+
503
+ </h3><div class="docstring">
504
+ <div class="discussion">
505
+
506
+ <p>Formats a <code>number</code> with grouped thousands using
507
+ <code>delimiter</code> (e.g., 12,324). You can customize the format in the
508
+ <code>options</code> hash.</p>
509
+
510
+
511
+ </div>
512
+ </div>
513
+ <div class="tags">
514
+
515
+ <div class="examples">
516
+ <p class="tag_title">Examples:</p>
517
+
518
+
519
+ <pre class="example code"><code><span class='id identifier rubyid_with_delimiter'>with_delimiter</span><span class='lparen'>(</span><span class='int'>12345678</span><span class='rparen'>)</span> <span class='comment'># =&gt; 12,345,678
520
+ </span><span class='id identifier rubyid_with_delimiter'>with_delimiter</span><span class='lparen'>(</span><span class='float'>12345678.05</span><span class='rparen'>)</span> <span class='comment'># =&gt; 12,345,678.05
521
+ </span><span class='id identifier rubyid_with_delimiter'>with_delimiter</span><span class='lparen'>(</span><span class='int'>12345678</span><span class='comma'>,</span> <span class='symbol'>:delimiter</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>.</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='comment'># =&gt; 12.345.678
522
+ </span><span class='id identifier rubyid_with_delimiter'>with_delimiter</span><span class='lparen'>(</span><span class='int'>12345678</span><span class='comma'>,</span> <span class='symbol'>:separator</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>,</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='comment'># =&gt; 12,345,678
523
+ </span><span class='id identifier rubyid_with_delimiter'>with_delimiter</span><span class='lparen'>(</span><span class='float'>98765432.98</span><span class='comma'>,</span> <span class='symbol'>:delimiter</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:separator</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>,</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
524
+ <span class='comment'># =&gt; 98 765 432,98</span></code></pre>
525
+
526
+ </div>
527
+
528
+ <div class="docstring">
529
+ <div class="discussion">
530
+
531
+
532
+ </div>
533
+ </div>
534
+ <div class="tags">
535
+ <p class="tag_title">Parameters:</p>
536
+ <ul class="param">
537
+
538
+ <li>
539
+
540
+ <span class='name'>number</span>
541
+
542
+
543
+ <span class='type'>(<tt>Fixnum</tt>, <tt>Float</tt>)</span>
544
+
545
+
546
+
547
+ &mdash;
548
+ <div class='inline'>
549
+ <p>Number value to format.</p>
550
+ </div>
551
+
552
+ </li>
553
+
554
+ <li>
555
+
556
+ <span class='name'>options</span>
557
+
558
+
559
+ <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="BB::Hash (module)">Hash</a></span></tt>)</span>
560
+
561
+
562
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
563
+
564
+
565
+ &mdash;
566
+ <div class='inline'>
567
+ <p>Options for formatter.</p>
568
+ </div>
569
+
570
+ </li>
571
+
572
+ </ul>
573
+
574
+
575
+
576
+
577
+
578
+
579
+ <p class="tag_title">Options Hash (<tt>options</tt>):</p>
580
+ <ul class="option">
581
+
582
+ <li>
583
+ <span class="name">:delimiter</span>
584
+ <span class="type">(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
585
+ <span class="default">
586
+
587
+ &mdash; default:
588
+ <tt>&quot;</tt>, <tt>&quot;</tt>
589
+
590
+ </span>
591
+
592
+ &mdash; <div class='inline'>
593
+ <p>Sets the thousands delimiter.</p>
594
+ </div>
595
+
596
+ </li>
597
+
598
+ <li>
599
+ <span class="name">:separator</span>
600
+ <span class="type">(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
601
+ <span class="default">
602
+
603
+ &mdash; default:
604
+ <tt>&quot;.&quot;</tt>
605
+
606
+ </span>
607
+
608
+ &mdash; <div class='inline'>
609
+ <p>Sets the separator between the units.</p>
610
+ </div>
611
+
612
+ </li>
613
+
614
+ </ul>
615
+
616
+
617
+
618
+ </div>
619
+
620
+ <p class="tag_title">Returns:</p>
621
+ <ul class="return">
622
+
623
+ <li>
624
+
625
+
626
+ <span class='type'>(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
627
+
628
+
629
+
630
+ &mdash;
631
+ <div class='inline'>
632
+ <p>The formatted representation of the number.</p>
633
+ </div>
634
+
635
+ </li>
636
+
637
+ </ul>
638
+
639
+ </div><table class="source_code">
640
+ <tr>
641
+ <td>
642
+ <pre class="lines">
643
+
644
+
645
+ 149
646
+ 150
647
+ 151
648
+ 152
649
+ 153
650
+ 154
651
+ 155
652
+ 156
653
+ 157
654
+ 158
655
+ 159
656
+ 160
657
+ 161
658
+ 162</pre>
659
+ </td>
660
+ <td>
661
+ <pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 149</span>
662
+
663
+ <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
+ <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>
665
+
666
+ <span class='id identifier rubyid_delimiter'>delimiter</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:delimiter</span><span class='rbracket'>]</span> <span class='op'>||</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>
667
+ <span class='id identifier rubyid_separator'>separator</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:separator</span><span class='rbracket'>]</span> <span class='op'>||</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>
668
+
669
+ <span class='kw'>begin</span>
670
+ <span class='id identifier rubyid_parts'>parts</span> <span class='op'>=</span> <span class='id identifier rubyid_number'>number</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</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>
671
+ <span class='id identifier rubyid_parts'>parts</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</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'>(\d)(?=(\d\d\d)+(?!\d))</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\\1</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_delimiter'>delimiter</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
672
+ <span class='id identifier rubyid_parts'>parts</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_separator'>separator</span><span class='rparen'>)</span>
673
+ <span class='kw'>rescue</span>
674
+ <span class='id identifier rubyid_number'>number</span>
675
+ <span class='kw'>end</span>
676
+ <span class='kw'>end</span></pre>
677
+ </td>
678
+ </tr>
679
+ </table>
680
+ </div>
681
+
682
+ <div class="method_details ">
683
+ <h3 class="signature " id="with_precision-class_method">
684
+
685
+ + (<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>) <strong>with_precision</strong>(number, options = {})
686
+
687
+
688
+
689
+
690
+
691
+ </h3><div class="docstring">
692
+ <div class="discussion">
693
+
694
+ <p>Formats a <code>number</code> with the specified level of
695
+ <code>:precision</code> (e.g., 112.32 has a precision of 2). You can
696
+ customize the format in the <code>options</code> hash.</p>
697
+
698
+
699
+ </div>
700
+ </div>
701
+ <div class="tags">
702
+
703
+ <div class="examples">
704
+ <p class="tag_title">Examples:</p>
705
+
706
+
707
+ <pre class="example code"><code><span class='id identifier rubyid_with_precision'>with_precision</span><span class='lparen'>(</span><span class='float'>111.2345</span><span class='rparen'>)</span> <span class='comment'># =&gt; 111.235
708
+ </span><span class='id identifier rubyid_with_precision'>with_precision</span><span class='lparen'>(</span><span class='float'>111.2345</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; 111.23
709
+ </span><span class='id identifier rubyid_with_precision'>with_precision</span><span class='lparen'>(</span><span class='int'>13</span><span class='comma'>,</span> <span class='symbol'>:precision</span> <span class='op'>=&gt;</span> <span class='int'>5</span><span class='rparen'>)</span> <span class='comment'># =&gt; 13.00000
710
+ </span><span class='id identifier rubyid_with_precision'>with_precision</span><span class='lparen'>(</span><span class='float'>389.32314</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; 389
711
+ </span><span class='id identifier rubyid_with_precision'>with_precision</span><span class='lparen'>(</span><span class='float'>1111.2345</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='comma'>,</span> <span class='symbol'>:delimiter</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>
712
+ <span class='comment'># =&gt; 1.111,23</span></code></pre>
713
+
714
+ </div>
715
+
716
+ <div class="docstring">
717
+ <div class="discussion">
718
+
719
+
720
+ </div>
721
+ </div>
722
+ <div class="tags">
723
+ <p class="tag_title">Parameters:</p>
724
+ <ul class="param">
725
+
726
+ <li>
727
+
728
+ <span class='name'>number</span>
729
+
730
+
731
+ <span class='type'>(<tt>Fixnum</tt>, <tt>Float</tt>)</span>
732
+
733
+
734
+
735
+ &mdash;
736
+ <div class='inline'>
737
+ <p>Number value to format.</p>
738
+ </div>
739
+
740
+ </li>
741
+
742
+ <li>
743
+
744
+ <span class='name'>options</span>
745
+
746
+
747
+ <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="BB::Hash (module)">Hash</a></span></tt>)</span>
748
+
749
+
750
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
751
+
752
+
753
+ &mdash;
754
+ <div class='inline'>
755
+ <p>Options for formatter.</p>
756
+ </div>
757
+
758
+ </li>
759
+
760
+ </ul>
761
+
762
+
763
+
764
+
765
+
766
+
767
+ <p class="tag_title">Options Hash (<tt>options</tt>):</p>
768
+ <ul class="option">
769
+
770
+ <li>
771
+ <span class="name">:precision</span>
772
+ <span class="type">(<tt>Fixnum</tt>)</span>
773
+ <span class="default">
774
+
775
+ &mdash; default:
776
+ <tt>3</tt>
777
+
778
+ </span>
779
+
780
+ &mdash; <div class='inline'>
781
+ <p>Sets the level of precision.</p>
782
+ </div>
783
+
784
+ </li>
785
+
786
+ <li>
787
+ <span class="name">:separator</span>
788
+ <span class="type">(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
789
+ <span class="default">
790
+
791
+ &mdash; default:
792
+ <tt>&quot;.&quot;</tt>
793
+
794
+ </span>
795
+
796
+ &mdash; <div class='inline'>
797
+ <p>Sets the separator between the units.</p>
798
+ </div>
799
+
800
+ </li>
801
+
802
+ <li>
803
+ <span class="name">:delimiter</span>
804
+ <span class="type">(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
805
+ <span class="default">
806
+
807
+ &mdash; default:
808
+ <tt>&quot;&quot;</tt>
809
+
810
+ </span>
811
+
812
+ &mdash; <div class='inline'>
813
+ <p>Sets the thousands delimiter.</p>
814
+ </div>
815
+
816
+ </li>
817
+
818
+ </ul>
819
+
820
+
821
+
822
+ </div>
823
+
824
+ <p class="tag_title">Returns:</p>
825
+ <ul class="return">
826
+
827
+ <li>
828
+
829
+
830
+ <span class='type'>(<tt><span class='object_link'><a href="String.html" title="BB::String (module)">String</a></span></tt>)</span>
831
+
832
+
833
+
834
+ &mdash;
835
+ <div class='inline'>
836
+ <p>The formatted representation of the number.</p>
837
+ </div>
838
+
839
+ </li>
840
+
841
+ </ul>
842
+
843
+ </div><table class="source_code">
844
+ <tr>
845
+ <td>
846
+ <pre class="lines">
847
+
848
+
849
+ 108
850
+ 109
851
+ 110
852
+ 111
853
+ 112
854
+ 113
855
+ 114
856
+ 115
857
+ 116
858
+ 117
859
+ 118
860
+ 119
861
+ 120
862
+ 121
863
+ 122
864
+ 123</pre>
865
+ </td>
866
+ <td>
867
+ <pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 108</span>
868
+
869
+ <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
+ <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>
871
+
872
+ <span class='id identifier rubyid_precision'>precision</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:precision</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='int'>3</span><span class='rparen'>)</span>
873
+ <span class='id identifier rubyid_separator'>separator</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:separator</span><span class='rbracket'>]</span> <span class='op'>||</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>
874
+ <span class='id identifier rubyid_delimiter'>delimiter</span> <span class='op'>||=</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:delimiter</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
875
+
876
+ <span class='kw'>begin</span>
877
+ <span class='id identifier rubyid_rounded_number'>rounded_number</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='const'>Float</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='rparen'>)</span> <span class='op'>*</span> <span class='lparen'>(</span><span class='int'>10</span> <span class='op'>**</span> <span class='id identifier rubyid_precision'>precision</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_round'>round</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span> <span class='op'>/</span> <span class='int'>10</span> <span class='op'>**</span> <span class='id identifier rubyid_precision'>precision</span>
878
+ <span class='id identifier rubyid_with_delimiter'>with_delimiter</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%01.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_precision'>precision</span><span class='embexpr_end'>}</span><span class='tstring_content'>f</span><span class='tstring_end'>&quot;</span></span> <span class='op'>%</span> <span class='id identifier rubyid_rounded_number'>rounded_number</span><span class='comma'>,</span>
879
+ <span class='symbol'>:separator</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_separator'>separator</span><span class='comma'>,</span>
880
+ <span class='symbol'>:delimiter</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_delimiter'>delimiter</span><span class='rparen'>)</span>
881
+ <span class='kw'>rescue</span>
882
+ <span class='id identifier rubyid_number'>number</span>
883
+ <span class='kw'>end</span>
884
+ <span class='kw'>end</span></pre>
885
+ </td>
886
+ </tr>
887
+ </table>
888
+ </div>
889
+
890
+ </div>
891
+
892
+ </div>
893
+
894
+ <div id="footer">
895
+ Generated on Sun Nov 22 18:31:14 2015 by
896
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
897
+ 0.8.5.2 (ruby-2.2.2).
898
+ </div>
899
+
900
+ </body>
901
+ </html>