docs/Bovem/ParserMethods/General/ClassMethods.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Bovem::ParserMethods::General::ClassMethods
— Documentation by YARD 0.9.7
</title>
<link rel="stylesheet" href="../../../css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="../../../css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
pathId = "Bovem::ParserMethods::General::ClassMethods";
relpath = '../../../';
</script>
<script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../../../class_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../../../_index.html">Index (C)</a> »
<span class='title'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span> » <span class='title'><span class='object_link'><a href="../../ParserMethods.html" title="Bovem::ParserMethods (module)">ParserMethods</a></span></span> » <span class='title'><span class='object_link'><a href="../General.html" title="Bovem::ParserMethods::General (module)">General</a></span></span>
»
<span class="title">ClassMethods</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../../../class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><h1>Module: Bovem::ParserMethods::General::ClassMethods
</h1>
<div class="box_info">
<dl>
<dt>Defined in:</dt>
<dd>lib/bovem/parser.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Class methods</p>
</div>
</div>
<div class="tags">
</div>
<h2>
Instance Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#find_command-instance_method" title="#find_command (instance method)">#<strong>find_command</strong>(arg, command, args: {}, separator: ":") ⇒ Hash|NilClass </a>
</span>
<span class="summary_desc"><div class='inline'><p>Finds a command which corresponds to an argument.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#parse-instance_method" title="#parse (instance method)">#<strong>parse</strong>(command, args) ⇒ Hash|NilClass </a>
</span>
<span class="summary_desc"><div class='inline'><p>Parses a command/application.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#smart_join-instance_method" title="#smart_join (instance method)">#<strong>smart_join</strong>(array, separator: ", ", last_separator: " and ", quote: "\"") ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Joins an array using multiple separators.</p>
</div></span>
</li>
</ul>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="find_command-instance_method">
#<strong>find_command</strong>(arg, command, args: {}, separator: ":") ⇒ <tt>Hash|NilClass</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Finds a command which corresponds to an argument.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>arg</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The string to match.</p>
</div>
</li>
<li>
<span class='name'>command</span>
<span class='type'>(<tt><span class='object_link'><a href="../../Command.html" title="Bovem::Command (class)">Command</a></span></tt>)</span>
—
<div class='inline'><p>The command to search subcommand in.</p>
</div>
</li>
<li>
<span class='name'>args</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The complete list of arguments passed.</p>
</div>
</li>
<li>
<span class='name'>separator</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The separator for joined syntax commands.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Hash|NilClass</tt>)</span>
—
<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>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
37
38
39
40
41
42
43
44
45
46
47
48</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/parser.rb', line 37</span>
<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='label'>args:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>separator:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>:</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</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='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>
<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>
<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
</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>
<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
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Errors.html" title="Bovem::Errors (module)">Errors</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Errors/Error.html" title="Bovem::Errors::Error (class)">Error</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="../../Errors/Error.html#initialize-instance_method" title="Bovem::Errors::Error#initialize (method)">new</a></span></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='id identifier rubyid_format_alternatives'>format_alternatives</span><span class='lparen'>(</span><span class='id identifier rubyid_matching'>matching</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="parse-instance_method">
#<strong>parse</strong>(command, args) ⇒ <tt>Hash|NilClass</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Parses a command/application.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>command</span>
<span class='type'>(<tt><span class='object_link'><a href="../../Command.html" title="Bovem::Command (class)">Command</a></span></tt>)</span>
—
<div class='inline'><p>The command or application to parse.</p>
</div>
</li>
<li>
<span class='name'>args</span>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>The arguments to parse.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Hash|NilClass</tt>)</span>
—
<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>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
55
56
57</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/parser.rb', line 55</span>
<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>
<span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Parser.html" title="Bovem::Parser (class)">Parser</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="../../Parser.html#parse-instance_method" title="Bovem::Parser#parse (method)">parse</a></span></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>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="smart_join-instance_method">
#<strong>smart_join</strong>(array, separator: ", ", last_separator: " and ", quote: "\"") ⇒ <tt>String</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Joins an array using multiple separators.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>array</span>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>The array to join.</p>
</div>
</li>
<li>
<span class='name'>separator</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The separator to use for all but last join.</p>
</div>
</li>
<li>
<span class='name'>last_separator</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The separator to use for the last join.</p>
</div>
</li>
<li>
<span class='name'>quote</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>If not nil, elements are quoted with that element.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The joined array.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
23
24
25
26
27
28</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/parser.rb', line 23</span>
<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='label'>separator:</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='label'>last_separator:</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='label'>quote:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<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>
<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>
<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='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_a'>a</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_quote'>quote</span><span class='embexpr_end'>}</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>
<span class='id identifier rubyid_perform_smart_join'>perform_smart_join</span><span class='lparen'>(</span><span class='id identifier rubyid_array'>array</span><span class='comma'>,</span> <span class='id identifier rubyid_last_separator'>last_separator</span><span class='comma'>,</span> <span class='id identifier rubyid_separator'>separator</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Thu Jan 12 16:10:58 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.7 (ruby-2.3.0).
</div>
</div>
</body>
</html>