mamertes 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.DS_Store +0 -0
- data/.gitignore +6 -0
- data/.travis-gemfile +15 -0
- data/.travis.yml +10 -0
- data/.yardopts +1 -0
- data/Gemfile +21 -0
- data/README.md +126 -0
- data/Rakefile +29 -0
- data/doc/Mamertes.html +155 -0
- data/doc/Mamertes/Application.html +3057 -0
- data/doc/Mamertes/Command.html +7031 -0
- data/doc/Mamertes/CommandMethods.html +125 -0
- data/doc/Mamertes/CommandMethods/Children.html +1286 -0
- data/doc/Mamertes/CommandMethods/Help.html +209 -0
- data/doc/Mamertes/Error.html +631 -0
- data/doc/Mamertes/Localizer.html +376 -0
- data/doc/Mamertes/Option.html +6671 -0
- data/doc/Mamertes/Parser.html +276 -0
- data/doc/Mamertes/ParserMethods.html +125 -0
- data/doc/Mamertes/ParserMethods/General.html +134 -0
- data/doc/Mamertes/ParserMethods/General/ClassMethods.html +574 -0
- data/doc/Mamertes/Version.html +189 -0
- data/doc/_index.html +276 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +338 -0
- data/doc/file.README.html +198 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +198 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +509 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/mamertes.rb +18 -0
- data/lib/mamertes/application.rb +206 -0
- data/lib/mamertes/command.rb +529 -0
- data/lib/mamertes/option.rb +236 -0
- data/lib/mamertes/parser.rb +317 -0
- data/lib/mamertes/version.rb +24 -0
- data/locales/en.yml +40 -0
- data/locales/it.yml +40 -0
- data/mamertes.gemspec +30 -0
- data/spec/coverage_helper.rb +20 -0
- data/spec/mamertes/application_spec.rb +181 -0
- data/spec/mamertes/command_spec.rb +526 -0
- data/spec/mamertes/option_spec.rb +274 -0
- data/spec/mamertes/parser_spec.rb +126 -0
- data/spec/spec_helper.rb +15 -0
- metadata +115 -0
@@ -0,0 +1,574 @@
|
|
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: Mamertes::ParserMethods::General::ClassMethods
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.6.2
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../../../css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../../../css/common.css" type="text/css" 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 (C)</a> »
|
35
|
+
<span class='title'><span class='object_link'><a href="../../../Mamertes.html" title="Mamertes (module)">Mamertes</a></span></span> » <span class='title'><span class='object_link'><a href="../../ParserMethods.html" title="Mamertes::ParserMethods (module)">ParserMethods</a></span></span> » <span class='title'><span class='object_link'><a href="../General.html" title="Mamertes::ParserMethods::General (module)">General</a></span></span>
|
36
|
+
»
|
37
|
+
<span class="title">ClassMethods</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: Mamertes::ParserMethods::General::ClassMethods
|
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/mamertes/parser.rb</dd>
|
83
|
+
|
84
|
+
</dl>
|
85
|
+
<div class="clear"></div>
|
86
|
+
|
87
|
+
<h2>Overview</h2><div class="docstring">
|
88
|
+
<div class="discussion">
|
89
|
+
<p>Class methods</p>
|
90
|
+
|
91
|
+
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
<div class="tags">
|
95
|
+
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
<h2>
|
106
|
+
Instance Method Summary
|
107
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
108
|
+
</h2>
|
109
|
+
|
110
|
+
<ul class="summary">
|
111
|
+
|
112
|
+
<li class="public ">
|
113
|
+
<span class="summary_signature">
|
114
|
+
|
115
|
+
<a href="#find_command-instance_method" title="#find_command (instance method)">- (Hash|NilClass) <strong>find_command</strong>(arg, command, args, separator = ":") </a>
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
</span>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
<span class="summary_desc"><div class='inline'><p>Finds a command which corresponds to an argument.</p>
|
130
|
+
</div></span>
|
131
|
+
|
132
|
+
</li>
|
133
|
+
|
134
|
+
|
135
|
+
<li class="public ">
|
136
|
+
<span class="summary_signature">
|
137
|
+
|
138
|
+
<a href="#parse-instance_method" title="#parse (instance method)">- (Hash|NilClass) <strong>parse</strong>(command, args) </a>
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
</span>
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
<span class="summary_desc"><div class='inline'><p>Parses a command/application.</p>
|
153
|
+
</div></span>
|
154
|
+
|
155
|
+
</li>
|
156
|
+
|
157
|
+
|
158
|
+
<li class="public ">
|
159
|
+
<span class="summary_signature">
|
160
|
+
|
161
|
+
<a href="#smart_join-instance_method" title="#smart_join (instance method)">- (String) <strong>smart_join</strong>(array, separator = ", ", last_separator = " and ", quote = "\"") </a>
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
</span>
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
<span class="summary_desc"><div class='inline'><p>Joins an array using multiple separators.</p>
|
176
|
+
</div></span>
|
177
|
+
|
178
|
+
</li>
|
179
|
+
|
180
|
+
|
181
|
+
</ul>
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
<div id="instance_method_details" class="method_details_list">
|
187
|
+
<h2>Instance Method Details</h2>
|
188
|
+
|
189
|
+
|
190
|
+
<div class="method_details first">
|
191
|
+
<h3 class="signature first" id="find_command-instance_method">
|
192
|
+
|
193
|
+
- (<tt>Hash|NilClass</tt>) <strong>find_command</strong>(arg, command, args, separator = ":")
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
</h3><div class="docstring">
|
200
|
+
<div class="discussion">
|
201
|
+
<p>Finds a command which corresponds to an argument.</p>
|
202
|
+
|
203
|
+
|
204
|
+
</div>
|
205
|
+
</div>
|
206
|
+
<div class="tags">
|
207
|
+
<p class="tag_title">Parameters:</p>
|
208
|
+
<ul class="param">
|
209
|
+
|
210
|
+
<li>
|
211
|
+
|
212
|
+
<span class='name'>arg</span>
|
213
|
+
|
214
|
+
|
215
|
+
<span class='type'>(<tt>String</tt>)</span>
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
—
|
220
|
+
<div class='inline'><p>The string to match.</p>
|
221
|
+
</div>
|
222
|
+
|
223
|
+
</li>
|
224
|
+
|
225
|
+
<li>
|
226
|
+
|
227
|
+
<span class='name'>command</span>
|
228
|
+
|
229
|
+
|
230
|
+
<span class='type'>(<tt><span class='object_link'><a href="../../Command.html" title="Mamertes::Command (class)">Command</a></span></tt>)</span>
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
—
|
235
|
+
<div class='inline'><p>The command to search subcommand in.</p>
|
236
|
+
</div>
|
237
|
+
|
238
|
+
</li>
|
239
|
+
|
240
|
+
<li>
|
241
|
+
|
242
|
+
<span class='name'>args</span>
|
243
|
+
|
244
|
+
|
245
|
+
<span class='type'>(<tt>String</tt>)</span>
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
—
|
250
|
+
<div class='inline'><p>The complete list of arguments passed.</p>
|
251
|
+
</div>
|
252
|
+
|
253
|
+
</li>
|
254
|
+
|
255
|
+
<li>
|
256
|
+
|
257
|
+
<span class='name'>separator</span>
|
258
|
+
|
259
|
+
|
260
|
+
<span class='type'>(<tt>String</tt>)</span>
|
261
|
+
|
262
|
+
|
263
|
+
<em class="default">(defaults to: <tt>":"</tt>)</em>
|
264
|
+
|
265
|
+
|
266
|
+
—
|
267
|
+
<div class='inline'><p>The separator for joined syntax commands.</p>
|
268
|
+
</div>
|
269
|
+
|
270
|
+
</li>
|
271
|
+
|
272
|
+
</ul>
|
273
|
+
|
274
|
+
<p class="tag_title">Returns:</p>
|
275
|
+
<ul class="return">
|
276
|
+
|
277
|
+
<li>
|
278
|
+
|
279
|
+
|
280
|
+
<span class='type'>(<tt>Hash|NilClass</tt>)</span>
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
—
|
285
|
+
<div class='inline'><p>An hash with <code>name</code> and <code>args</code> keys if a valid subcommand is found, <code>nil</code> otherwise.</p>
|
286
|
+
</div>
|
287
|
+
|
288
|
+
</li>
|
289
|
+
|
290
|
+
</ul>
|
291
|
+
|
292
|
+
</div><table class="source_code">
|
293
|
+
<tr>
|
294
|
+
<td>
|
295
|
+
<pre class="lines">
|
296
|
+
|
297
|
+
|
298
|
+
37
|
299
|
+
38
|
300
|
+
39
|
301
|
+
40
|
302
|
+
41
|
303
|
+
42
|
304
|
+
43
|
305
|
+
44
|
306
|
+
45
|
307
|
+
46
|
308
|
+
47
|
309
|
+
48
|
310
|
+
49
|
311
|
+
50
|
312
|
+
51
|
313
|
+
52</pre>
|
314
|
+
</td>
|
315
|
+
<td>
|
316
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/parser.rb', line 37</span>
|
317
|
+
|
318
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_find_command'>find_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_separator'>separator</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>:</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
319
|
+
<span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span>
|
320
|
+
|
321
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_commands'>commands</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='kw'>then</span>
|
322
|
+
<span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='id identifier rubyid_adjust_command'>adjust_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_separator'>separator</span><span class='rparen'>)</span>
|
323
|
+
|
324
|
+
<span class='id identifier rubyid_matching'>matching</span> <span class='op'>=</span> <span class='id identifier rubyid_match_subcommands'>match_subcommands</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
325
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_matching'>matching</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='comment'># Found a command
|
326
|
+
</span> <span class='lbrace'>{</span><span class='label'>name:</span> <span class='id identifier rubyid_matching'>matching</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>args:</span> <span class='id identifier rubyid_args'>args</span><span class='rbrace'>}</span>
|
327
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_matching'>matching</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>></span> <span class='int'>1</span> <span class='comment'># Ambiguous match
|
328
|
+
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Error</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='symbol'>:ambiguous_command</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_ambigous_command'>ambigous_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_smart_join'>smart_join</span><span class='lparen'>(</span><span class='id identifier rubyid_matching'>matching</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
329
|
+
<span class='kw'>end</span>
|
330
|
+
<span class='kw'>else</span>
|
331
|
+
<span class='kw'>nil</span>
|
332
|
+
<span class='kw'>end</span>
|
333
|
+
<span class='kw'>end</span></pre>
|
334
|
+
</td>
|
335
|
+
</tr>
|
336
|
+
</table>
|
337
|
+
</div>
|
338
|
+
|
339
|
+
<div class="method_details ">
|
340
|
+
<h3 class="signature " id="parse-instance_method">
|
341
|
+
|
342
|
+
- (<tt>Hash|NilClass</tt>) <strong>parse</strong>(command, args)
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
</h3><div class="docstring">
|
349
|
+
<div class="discussion">
|
350
|
+
<p>Parses a command/application.</p>
|
351
|
+
|
352
|
+
|
353
|
+
</div>
|
354
|
+
</div>
|
355
|
+
<div class="tags">
|
356
|
+
<p class="tag_title">Parameters:</p>
|
357
|
+
<ul class="param">
|
358
|
+
|
359
|
+
<li>
|
360
|
+
|
361
|
+
<span class='name'>command</span>
|
362
|
+
|
363
|
+
|
364
|
+
<span class='type'>(<tt><span class='object_link'><a href="../../Command.html" title="Mamertes::Command (class)">Command</a></span></tt>)</span>
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
—
|
369
|
+
<div class='inline'><p>The command or application to parse.</p>
|
370
|
+
</div>
|
371
|
+
|
372
|
+
</li>
|
373
|
+
|
374
|
+
<li>
|
375
|
+
|
376
|
+
<span class='name'>args</span>
|
377
|
+
|
378
|
+
|
379
|
+
<span class='type'>(<tt>Array</tt>)</span>
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
—
|
384
|
+
<div class='inline'><p>The arguments to parse.</p>
|
385
|
+
</div>
|
386
|
+
|
387
|
+
</li>
|
388
|
+
|
389
|
+
</ul>
|
390
|
+
|
391
|
+
<p class="tag_title">Returns:</p>
|
392
|
+
<ul class="return">
|
393
|
+
|
394
|
+
<li>
|
395
|
+
|
396
|
+
|
397
|
+
<span class='type'>(<tt>Hash|NilClass</tt>)</span>
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
—
|
402
|
+
<div class='inline'><p>An hash with <code>name</code> (of a subcommand to execute) and <code>args</code> keys if a valid subcommand is found, <code>nil</code> otherwise.</p>
|
403
|
+
</div>
|
404
|
+
|
405
|
+
</li>
|
406
|
+
|
407
|
+
</ul>
|
408
|
+
|
409
|
+
</div><table class="source_code">
|
410
|
+
<tr>
|
411
|
+
<td>
|
412
|
+
<pre class="lines">
|
413
|
+
|
414
|
+
|
415
|
+
59
|
416
|
+
60
|
417
|
+
61</pre>
|
418
|
+
</td>
|
419
|
+
<td>
|
420
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/parser.rb', line 59</span>
|
421
|
+
|
422
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
423
|
+
<span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
424
|
+
<span class='kw'>end</span></pre>
|
425
|
+
</td>
|
426
|
+
</tr>
|
427
|
+
</table>
|
428
|
+
</div>
|
429
|
+
|
430
|
+
<div class="method_details ">
|
431
|
+
<h3 class="signature " id="smart_join-instance_method">
|
432
|
+
|
433
|
+
- (<tt>String</tt>) <strong>smart_join</strong>(array, separator = ", ", last_separator = " and ", quote = "\"")
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
</h3><div class="docstring">
|
440
|
+
<div class="discussion">
|
441
|
+
<p>Joins an array using multiple separators.</p>
|
442
|
+
|
443
|
+
|
444
|
+
</div>
|
445
|
+
</div>
|
446
|
+
<div class="tags">
|
447
|
+
<p class="tag_title">Parameters:</p>
|
448
|
+
<ul class="param">
|
449
|
+
|
450
|
+
<li>
|
451
|
+
|
452
|
+
<span class='name'>array</span>
|
453
|
+
|
454
|
+
|
455
|
+
<span class='type'>(<tt>Array</tt>)</span>
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
—
|
460
|
+
<div class='inline'><p>The array to join.</p>
|
461
|
+
</div>
|
462
|
+
|
463
|
+
</li>
|
464
|
+
|
465
|
+
<li>
|
466
|
+
|
467
|
+
<span class='name'>separator</span>
|
468
|
+
|
469
|
+
|
470
|
+
<span class='type'>(<tt>String</tt>)</span>
|
471
|
+
|
472
|
+
|
473
|
+
<em class="default">(defaults to: <tt>", "</tt>)</em>
|
474
|
+
|
475
|
+
|
476
|
+
—
|
477
|
+
<div class='inline'><p>The separator to use for all but last join.</p>
|
478
|
+
</div>
|
479
|
+
|
480
|
+
</li>
|
481
|
+
|
482
|
+
<li>
|
483
|
+
|
484
|
+
<span class='name'>last_separator</span>
|
485
|
+
|
486
|
+
|
487
|
+
<span class='type'>(<tt>String</tt>)</span>
|
488
|
+
|
489
|
+
|
490
|
+
<em class="default">(defaults to: <tt>" and "</tt>)</em>
|
491
|
+
|
492
|
+
|
493
|
+
—
|
494
|
+
<div class='inline'><p>The separator to use for the last join.</p>
|
495
|
+
</div>
|
496
|
+
|
497
|
+
</li>
|
498
|
+
|
499
|
+
<li>
|
500
|
+
|
501
|
+
<span class='name'>quote</span>
|
502
|
+
|
503
|
+
|
504
|
+
<span class='type'>(<tt>String</tt>)</span>
|
505
|
+
|
506
|
+
|
507
|
+
<em class="default">(defaults to: <tt>"\""</tt>)</em>
|
508
|
+
|
509
|
+
|
510
|
+
—
|
511
|
+
<div class='inline'><p>If not nil, elements are quoted with that element.</p>
|
512
|
+
</div>
|
513
|
+
|
514
|
+
</li>
|
515
|
+
|
516
|
+
</ul>
|
517
|
+
|
518
|
+
<p class="tag_title">Returns:</p>
|
519
|
+
<ul class="return">
|
520
|
+
|
521
|
+
<li>
|
522
|
+
|
523
|
+
|
524
|
+
<span class='type'>(<tt>String</tt>)</span>
|
525
|
+
|
526
|
+
|
527
|
+
|
528
|
+
—
|
529
|
+
<div class='inline'><p>The joined array.</p>
|
530
|
+
</div>
|
531
|
+
|
532
|
+
</li>
|
533
|
+
|
534
|
+
</ul>
|
535
|
+
|
536
|
+
</div><table class="source_code">
|
537
|
+
<tr>
|
538
|
+
<td>
|
539
|
+
<pre class="lines">
|
540
|
+
|
541
|
+
|
542
|
+
23
|
543
|
+
24
|
544
|
+
25
|
545
|
+
26
|
546
|
+
27
|
547
|
+
28</pre>
|
548
|
+
</td>
|
549
|
+
<td>
|
550
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/parser.rb', line 23</span>
|
551
|
+
|
552
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_smart_join'>smart_join</span><span class='lparen'>(</span><span class='id identifier rubyid_array'>array</span><span class='comma'>,</span> <span class='id identifier rubyid_separator'>separator</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>, </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_last_separator'>last_separator</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> and </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_quote'>quote</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
553
|
+
<span class='id identifier rubyid_separator'>separator</span> <span class='op'>=</span> <span class='id identifier rubyid_separator'>separator</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span>
|
554
|
+
<span class='id identifier rubyid_last_separator'>last_separator</span> <span class='op'>=</span> <span class='id identifier rubyid_last_separator'>last_separator</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span>
|
555
|
+
<span class='id identifier rubyid_array'>array</span> <span class='op'>=</span> <span class='id identifier rubyid_array'>array</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_a'>a</span><span class='op'>|</span> <span class='id identifier rubyid_quote'>quote</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_quote'>quote</span><span class='rbrace'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_a'>a</span><span class='rbrace'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_quote'>quote</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span> <span class='op'>:</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span> <span class='rbrace'>}</span>
|
556
|
+
<span class='id identifier rubyid_array'>array</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'><</span> <span class='int'>2</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='id identifier rubyid_array'>array</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='lparen'>(</span><span class='id identifier rubyid_array'>array</span><span class='lbracket'>[</span><span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_array'>array</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>-</span> <span class='int'>1</span><span class='rbracket'>]</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> <span class='op'>+</span> <span class='id identifier rubyid_last_separator'>last_separator</span> <span class='op'>+</span> <span class='id identifier rubyid_array'>array</span><span class='lbracket'>[</span><span class='op'>-</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
557
|
+
<span class='kw'>end</span></pre>
|
558
|
+
</td>
|
559
|
+
</tr>
|
560
|
+
</table>
|
561
|
+
</div>
|
562
|
+
|
563
|
+
</div>
|
564
|
+
|
565
|
+
</div>
|
566
|
+
|
567
|
+
<div id="footer">
|
568
|
+
Generated on Sat Aug 10 16:23:08 2013 by
|
569
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
570
|
+
0.8.6.2 (ruby-1.9.3).
|
571
|
+
</div>
|
572
|
+
|
573
|
+
</body>
|
574
|
+
</html>
|