docs/Lazier/String.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Lazier::String
— Documentation by YARD 0.9.5
</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 = "Lazier::String";
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"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../_index.html">Index (S)</a> »
<span class='title'><span class='object_link'><a href="../Lazier.html" title="Lazier (module)">Lazier</a></span></span>
»
<span class="title">String</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>
<iframe id="search_frame" src="../class_list.html"></iframe>
<div id="content"><h1>Module: Lazier::String
</h1>
<div class="box_info">
<dl>
<dt>Extended by:</dt>
<dd>ActiveSupport::Concern</dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib/lazier/string.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Extensions for the <code>String</code> class.</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="#ensure_url_with_scheme-instance_method" title="#ensure_url_with_scheme (instance method)">#<strong>ensure_url_with_scheme</strong>(protocol = "http", secure: false) ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Makes sure the string starts with the scheme for the specified protocol.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#ensure_valid_utf8-instance_method" title="#ensure_valid_utf8 (instance method)">#<strong>ensure_valid_utf8</strong>(replacement = "") ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Makes sure the string only contains valid UTF-8 sequences.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#remove_accents-instance_method" title="#remove_accents (instance method)">#<strong>remove_accents</strong> ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Removes accents from the string, normalizing to the normal letter.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#tokenize-instance_method" title="#tokenize (instance method)">#<strong>tokenize</strong>(no_blanks: true, strip: true, no_duplicates: false, pattern: /\s*,\s*/, presence_method: :present?) ⇒ Array </a>
</span>
<span class="summary_desc"><div class='inline'><p>Splits a string containing tokens using a specified pattern and applying some sanitizations.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#value-instance_method" title="#value (instance method)">#<strong>value</strong> ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns the string itself for use in form helpers.</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="ensure_url_with_scheme-instance_method">
#<strong>ensure_url_with_scheme</strong>(protocol = "http", secure: false) ⇒ <tt><span class='object_link'><a href="Object.html" title="Lazier::Object (module)">Object</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Makes sure the string starts with the scheme for the specified protocol.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>protocol</span>
<span class='type'>(<tt><span class='object_link'><a href="" title="Lazier::String (module)">String</a></span></tt>)</span>
<em class="default">(defaults to: <tt>"http"</tt>)</em>
—
<div class='inline'><p>The protocol for the URL.</p>
</div>
</li>
<li>
<span class='name'>secure</span>
<span class='type'>(<tt><span class='object_link'><a href="Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
—
<div class='inline'><p>If the scheme should be secure or not.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
24
25
26
27</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/string.rb', line 24</span>
<span class='kw'>def</span> <span class='id identifier rubyid_ensure_url_with_scheme'>ensure_url_with_scheme</span><span class='lparen'>(</span><span class='id identifier rubyid_protocol'>protocol</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>http</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>secure:</span> <span class='kw'>false</span><span class='rparen'>)</span>
<span class='id identifier rubyid_schema'>schema</span> <span class='op'>=</span> <span class='id identifier rubyid_protocol'>protocol</span> <span class='op'>+</span> <span class='lparen'>(</span><span class='id identifier rubyid_secure'>secure</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>s</span><span class='tstring_end'>"</span></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='kw'>self</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_protocol'>protocol</span><span class='embexpr_end'>}</span><span class='tstring_content'>(s?):\/\/)</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_schema'>schema</span><span class='embexpr_end'>}</span><span class='tstring_content'>://</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='op'>:</span> <span class='kw'>self</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="ensure_valid_utf8-instance_method">
#<strong>ensure_valid_utf8</strong>(replacement = "") ⇒ <tt><span class='object_link'><a href="" title="Lazier::String (module)">String</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Makes sure the string only contains valid UTF-8 sequences.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>replacement</span>
<span class='type'>(<tt><span class='object_link'><a href="" title="Lazier::String (module)">String</a></span></tt>)</span>
<em class="default">(defaults to: <tt>""</tt>)</em>
—
<div class='inline'><p>The string to use to replace invalid sequences.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt><span class='object_link'><a href="" title="Lazier::String (module)">String</a></span></tt>)</span>
—
<div class='inline'><p>The string with any invalid UTF-8 sequences replaced.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
15
16
17
18</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/string.rb', line 15</span>
<span class='kw'>def</span> <span class='id identifier rubyid_ensure_valid_utf8'>ensure_valid_utf8</span><span class='lparen'>(</span><span class='id identifier rubyid_replacement'>replacement</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='comment'># This odd line is because if need to specify a different encoding (without losing infos) to replace invalid bytes and then we go back to utf-8
</span> <span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>utf-16</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>invalid:</span> <span class='symbol'>:replace</span><span class='comma'>,</span> <span class='label'>undef:</span> <span class='symbol'>:replace</span><span class='comma'>,</span> <span class='label'>replace:</span> <span class='id identifier rubyid_replacement'>replacement</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>utf-8</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="remove_accents-instance_method">
#<strong>remove_accents</strong> ⇒ <tt><span class='object_link'><a href="Object.html" title="Lazier::Object (module)">Object</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Removes accents from the string, normalizing to the normal letter.</p>
<p><code>ruby
"èòàù".remove_accents
# => "eoau"
</code></p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'></span>
<div class='inline'><p>The string with all accents removed.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
60
61
62</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/string.rb', line 60</span>
<span class='kw'>def</span> <span class='id identifier rubyid_remove_accents'>remove_accents</span>
<span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_transliterate'>transliterate</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="tokenize-instance_method">
#<strong>tokenize</strong>(no_blanks: true, strip: true, no_duplicates: false, pattern: /\s*,\s*/, presence_method: :present?) ⇒ <tt>Array</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Splits a string containing tokens using a specified pattern and applying some sanitizations.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>no_blanks</span>
<span class='type'>(<tt><span class='object_link'><a href="Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
—
<div class='inline'><p>If filter out blank tokens.</p>
</div>
</li>
<li>
<span class='name'>strip</span>
<span class='type'>(<tt><span class='object_link'><a href="Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
—
<div class='inline'><p>If strip single tokens.</p>
</div>
</li>
<li>
<span class='name'>no_duplicates</span>
<span class='type'>(<tt><span class='object_link'><a href="Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
—
<div class='inline'><p>If return uniques elements.</p>
</div>
</li>
<li>
<span class='name'>pattern</span>
<span class='type'>(<tt><span class='object_link'><a href="" title="Lazier::String (module)">String</a></span>|Regexp</tt>)</span>
—
<div class='inline'><p>The pattern to use.</p>
</div>
</li>
<li>
<span class='name'>presence_method</span>
<span class='type'>(<tt>Symbol</tt>)</span>
—
<div class='inline'><p>The method to use to check if a token is present or not.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>An array of tokens.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
44
45
46
47
48
49
50</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/string.rb', line 44</span>
<span class='kw'>def</span> <span class='id identifier rubyid_tokenize'>tokenize</span><span class='lparen'>(</span><span class='label'>no_blanks:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>strip:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>no_duplicates:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='label'>pattern:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\s*,\s*</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>presence_method:</span> <span class='symbol'>:present?</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='id identifier rubyid_pattern'>pattern</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_map!'>map!</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_strip'>strip</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_select!'>select!</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_presence_method'>presence_method</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_no_blanks'>no_blanks</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_uniq!'>uniq!</span> <span class='kw'>if</span> <span class='id identifier rubyid_no_duplicates'>no_duplicates</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="value-instance_method">
#<strong>value</strong> ⇒ <tt><span class='object_link'><a href="" title="Lazier::String (module)">String</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns the string itself for use in form helpers.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt><span class='object_link'><a href="" title="Lazier::String (module)">String</a></span></tt>)</span>
—
<div class='inline'><p>The string itself.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
32
33
34</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/string.rb', line 32</span>
<span class='kw'>def</span> <span class='id identifier rubyid_value'>value</span>
<span class='kw'>self</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Thu Nov 10 11:39:24 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.5 (ruby-2.3.0).
</div>
</div>
</body>
</html>