<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta name="Content-Type" content="text/html; charset=UTF-8" /> <title>Class: TableFu::Formatting</title> <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" /> <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" /> <script type="text/javascript" charset="utf-8"> relpath = '..'; if (relpath != '') 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> <script type="text/javascript" charset="utf-8"> if (window.top.frames.main) document.body.className = 'frames'; </script> <div id="header"> <div id="menu"> <a href="../_index.html">Index (F)</a> » <span class='title'><a href="../TableFu.html" title="TableFu (class)">TableFu</a></span> » <span class="title">Formatting</span> <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div> </div> <div id="search"> <a id="class_list_link" href="#">Class List</a> <a id="method_list_link" href="#">Method List</a> <a id ="file_list_link" href="#">File List</a> </div> <div class="clear"></div> </div> <iframe id="search_frame"></iframe> <div id="content"><h1>Class: TableFu::Formatting </h1> <dl class="box"> <dt class="r1">Inherits:</dt> <dd class="r1"> <span class="inheritName">Object</span> <ul class="fullTree"> <li>Object</li> <li class="next">TableFu::Formatting</li> </ul> <a href="#" class="inheritanceTree">show all</a> </dd> <dt class="r2 last">Defined in:</dt> <dd class="r2 last">lib/table_fu/formatting.rb</dd> </dl> <div class="clear"></div> <h2>Overview</h2><div class="docstring"> <div class="discussion"> <p> Override this class to add more formatting methods </p> <p> Methods expect one or more arguments, which could be nil, and should return the appropriate formatting and style. </p> </div> </div> <div class="tags"> </div> <h2>Class Method Summary</h2> <ul class="summary"> <li class="public "> <span class="summary_signature"> <a href="#currency-class_method" title="currency (class method)">+ (Object) <strong>currency</strong>(num) </a> </span> <span class="summary_desc"> Returns a currency formatted number. </span> </li> <li class="public "> <span class="summary_signature"> <a href="#last_name-class_method" title="last_name (class method)">+ (Object) <strong>last_name</strong>(name) </a> </span> <span class="summary_desc"> Returns the last name of a name . </span> </li> <li class="public "> <span class="summary_signature"> <a href="#last_name_first_name-class_method" title="last_name_first_name (class method)">+ (Object) <strong>last_name_first_name</strong>(name) </a> </span> <span class="summary_desc"> Returns that last name first of a name. </span> </li> <li class="public "> <span class="summary_signature"> <a href="#link-class_method" title="link (class method)">+ (Object) <strong>link</strong>(linkname, href) </a> </span> <span class="summary_desc"> Returns an html link constructed from link, linkname. </span> </li> <li class="public "> <span class="summary_signature"> <a href="#method_missing-class_method" title="method_missing (class method)">+ (Object) <strong>method_missing</strong>(method) </a> </span> <span class="summary_desc"> Returns an error message if the given formatter isn’t available. </span> </li> </ul> <div id="class_method_details" class="method_details_list"> <h2>Class Method Details</h2> <div class="method_details first"> <p class="signature first" id="currency-class_method"> + (<tt>Object</tt>) <strong>currency</strong>(num) </p><div class="docstring"> <div class="discussion"> <p> Returns a currency formatted number </p> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 10 11 12 13 14 15 16 17 18</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/table_fu/formatting.rb', line 10</span> <span class='def def kw'>def</span> <span class='currency identifier id'>currency</span><span class='lparen token'>(</span><span class='num identifier id'>num</span><span class='rparen token'>)</span> <span class='begin begin kw'>begin</span> <span class='parts identifier id'>parts</span> <span class='assign token'>=</span> <span class='num identifier id'>num</span><span class='dot token'>.</span><span class='to_s identifier id'>to_s</span><span class='dot token'>.</span><span class='split identifier id'>split</span><span class='lparen token'>(</span><span class='string val'>'.'</span><span class='rparen token'>)</span> <span class='parts identifier id'>parts</span><span class='lbrack token'>[</span><span class='integer val'>0</span><span class='rbrack token'>]</span><span class='dot token'>.</span><span class='gsub! fid id'>gsub!</span><span class='lparen token'>(</span><span class='regexp val'>/(\d)(?=(\d\d\d)+(?!\d))/</span><span class='comma token'>,</span> <span class='string val'>"\\1,"</span><span class='rparen token'>)</span> <span class='dstring node'>"$#{parts.join('.')}"</span> <span class='rescue rescue kw'>rescue</span> <span class='num identifier id'>num</span> <span class='end end kw'>end</span> <span class='end end kw'>end</span> </pre> </td> </tr> </table> </div> <div class="method_details "> <p class="signature " id="last_name-class_method"> + (<tt>Object</tt>) <strong>last_name</strong>(name) </p><div class="docstring"> <div class="discussion"> <p> Returns the last name of a name </p> <pre class="code"> <span class='assign token'>=</span><span class='gt op'>></span> <span class='last_name identifier id'>last_name</span><span class='lparen token'>(</span><span class='string val'>"Jeff Larson"</span><span class='rparen token'>)</span> <span class='rshft op'>>></span> <span class='Larson constant id'>Larson</span> </pre> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 23 24 25 26 27 28 29 30</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/table_fu/formatting.rb', line 23</span> <span class='def def kw'>def</span> <span class='last_name identifier id'>last_name</span><span class='lparen token'>(</span><span class='name identifier id'>name</span><span class='rparen token'>)</span> <span class='name identifier id'>name</span><span class='dot token'>.</span><span class='strip! fid id'>strip!</span> <span class='if if kw'>if</span> <span class='name identifier id'>name</span><span class='dot token'>.</span><span class='match identifier id'>match</span><span class='lparen token'>(</span><span class='regexp val'>/\s(\w+)$/</span><span class='rparen token'>)</span> <span class='$1 nth_ref id'>$1</span> <span class='else else kw'>else</span> <span class='name identifier id'>name</span> <span class='end end kw'>end</span> <span class='end end kw'>end</span> </pre> </td> </tr> </table> </div> <div class="method_details "> <p class="signature " id="last_name_first_name-class_method"> + (<tt>Object</tt>) <strong>last_name_first_name</strong>(name) </p><div class="docstring"> <div class="discussion"> <p> Returns that last name first of a name </p> <pre class="code"> <span class='assign token'>=</span><span class='gt op'>></span> <span class='last_name_first_name identifier id'>last_name_first_name</span><span class='lparen token'>(</span><span class='string val'>"Jeff Larson"</span><span class='rparen token'>)</span> <span class='rshft op'>>></span> <span class='Larson constant id'>Larson</span><span class='comma token'>,</span> <span class='Jeff constant id'>Jeff</span> </pre> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 34 35 36 37 38</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/table_fu/formatting.rb', line 34</span> <span class='def def kw'>def</span> <span class='last_name_first_name identifier id'>last_name_first_name</span><span class='lparen token'>(</span><span class='name identifier id'>name</span><span class='rparen token'>)</span> <span class='last identifier id'>last</span> <span class='assign token'>=</span> <span class='last_name identifier id'>last_name</span><span class='lparen token'>(</span><span class='name identifier id'>name</span><span class='rparen token'>)</span> <span class='first identifier id'>first</span> <span class='assign token'>=</span> <span class='name identifier id'>name</span><span class='dot token'>.</span><span class='gsub identifier id'>gsub</span><span class='lparen token'>(</span><span class='last identifier id'>last</span><span class='comma token'>,</span> <span class='string val'>''</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='strip identifier id'>strip</span> <span class='dstring node'>"#{last}, #{first}"</span> <span class='end end kw'>end</span> </pre> </td> </tr> </table> </div> <div class="method_details "> <p class="signature " id="link-class_method"> + (<tt>Object</tt>) <strong>link</strong>(linkname, href) </p><div class="docstring"> <div class="discussion"> <p> Returns an html link constructed from link, linkname </p> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 41 42 43</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/table_fu/formatting.rb', line 41</span> <span class='def def kw'>def</span> <span class='link identifier id'>link</span><span class='lparen token'>(</span><span class='linkname identifier id'>linkname</span><span class='comma token'>,</span> <span class='href identifier id'>href</span><span class='rparen token'>)</span> <span class='dstring node'>"<a href='#{href}' title='#{linkname}'>#{linkname}</a>"</span> <span class='end end kw'>end</span> </pre> </td> </tr> </table> </div> <div class="method_details "> <p class="signature " id="method_missing-class_method"> + (<tt>Object</tt>) <strong>method_missing</strong>(method) </p><div class="docstring"> <div class="discussion"> <p> Returns an error message if the given formatter isn’t available </p> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 46 47 48</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/table_fu/formatting.rb', line 46</span> <span class='def def kw'>def</span> <span class='method_missing identifier id'>method_missing</span><span class='lparen token'>(</span><span class='method identifier id'>method</span><span class='rparen token'>)</span> <span class='dstring node'>"#{method.to_s} not a valid formatter!"</span> <span class='end end kw'>end</span> </pre> </td> </tr> </table> </div> </div> </div> <div id="footer"> Generated on Tue Mar 9 17:16:38 2010 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a> 0.5.3 (ruby-1.8.7). </div> </body> </html>