<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> Class: Brauser::Definition — Documentation by YARD 0.8.7.4 </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"> hasFrames = window.top.frames.main ? true : false; relpath = '../'; framesUrl = "../frames.html#!Brauser/Definition.html"; </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 id="header"> <div id="menu"> <a href="../_index.html">Index (D)</a> » <span class='title'><span class='object_link'><a href="../Brauser.html" title="Brauser (module)">Brauser</a></span></span> » <span class="title">Definition</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 class="full_list_link" id="class_list_link" href="../class_list.html"> Class List </a> <a class="full_list_link" id="method_list_link" href="../method_list.html"> Method List </a> <a class="full_list_link" id="file_list_link" href="../file_list.html"> File List </a> </div> <div class="clear"></div> </div> <iframe id="search_frame"></iframe> <div id="content"><h1>Class: Brauser::Definition </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">Brauser::Definition</li> </ul> <a href="#" class="inheritanceTree">show all</a> </dd> <dt class="r2 last">Defined in:</dt> <dd class="r2 last">lib/brauser/definition.rb</dd> </dl> <div class="clear"></div> <h2>Overview</h2><div class="docstring"> <div class="discussion"> <p>A class which hold a definition of a browser, a platform or a language This class represents a detection of the current user browser.</p> </div> </div> <div class="tags"> </div> <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2> <ul class="summary"> <li class="public "> <span class="summary_signature"> <a href="#label-instance_method" title="#label (instance method)">- (String) <strong>label</strong> </a> </span> <span class="summary_desc"><div class='inline'><p>A human readable label for this definition.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#primary-instance_method" title="#primary (instance method)">- (String|Symbol|Proc) <strong>primary</strong> </a> </span> <span class="summary_desc"><div class='inline'><p>The primary matcher of this definition.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#secondary-instance_method" title="#secondary (instance method)">- (String|Symbol|Proc) <strong>secondary</strong> </a> </span> <span class="summary_desc"><div class='inline'><p>The secondary matcher of this definition.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#tag-instance_method" title="#tag (instance method)">- (String|Symbol) <strong>tag</strong> </a> </span> <span class="summary_desc"><div class='inline'><p>An identifier for this definition.</p> </div></span> </li> </ul> <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="#initialize-instance_method" title="#initialize (instance method)">- (Definition) <strong>initialize</strong>(tag = nil, label = nil, primary = nil, secondary = nil) </a> </span> <span class="note title constructor">constructor</span> <span class="summary_desc"><div class='inline'><p>Creates a new definition.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#match-instance_method" title="#match (instance method)">- (Object|NilClass) <strong>match</strong>(type, *args) </a> </span> <span class="summary_desc"><div class='inline'><p>Performs a match of this definition.</p> </div></span> </li> </ul> <div id="constructor_details" class="method_details_list"> <h2>Constructor Details</h2> <div class="method_details first"> <h3 class="signature first" id="initialize-instance_method"> - (<tt><span class='object_link'><a href="" title="Brauser::Definition (class)">Definition</a></span></tt>) <strong>initialize</strong>(tag = nil, label = nil, primary = nil, secondary = nil) </h3><div class="docstring"> <div class="discussion"> <p>Creates a new definition.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>tag</span> <span class='type'>(<tt>String|Symbol</tt>)</span> <em class="default">(defaults to: <tt>nil</tt>)</em> — <div class='inline'><p>An identifier for this definition.</p> </div> </li> <li> <span class='name'>label</span> <span class='type'>(<tt>String</tt>)</span> <em class="default">(defaults to: <tt>nil</tt>)</em> — <div class='inline'><p>A human readable label for this definition.</p> </div> </li> <li> <span class='name'>primary</span> <span class='type'>(<tt>String|Symbol|Proc</tt>)</span> <em class="default">(defaults to: <tt>nil</tt>)</em> — <div class='inline'><p>The primary matcher of this definition.</p> </div> </li> <li> <span class='name'>secondary</span> <span class='type'>(<tt>String|Symbol|Proc</tt>)</span> <em class="default">(defaults to: <tt>nil</tt>)</em> — <div class='inline'><p>The secondary matcher of this definition.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 28 29 30 31 32 33</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/brauser/definition.rb', line 28</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>if</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>if</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>if</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>if</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> </div> <div id="instance_attr_details" class="attr_details"> <h2>Instance Attribute Details</h2> <span id="label=-instance_method"></span> <div class="method_details first"> <h3 class="signature first" id="label-instance_method"> - (<tt>String</tt>) <strong>label</strong> </h3><div class="docstring"> <div class="discussion"> <p>Returns A human readable label for this definition.</p> </div> </div> <div class="tags"> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>String</tt>)</span> — <div class='inline'><p>A human readable label for this definition.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/brauser/definition.rb', line 19</span> <span class='kw'>class</span> <span class='const'>Definition</span> <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:tag</span><span class='comma'>,</span> <span class='symbol'>:label</span><span class='comma'>,</span> <span class='symbol'>:primary</span><span class='comma'>,</span> <span class='symbol'>:secondary</span> <span class='comment'># Creates a new definition. </span> <span class='comment'># </span> <span class='comment'># @param tag [String|Symbol] An identifier for this definition. </span> <span class='comment'># @param label [String] A human readable label for this definition. </span> <span class='comment'># @param primary [String|Symbol|Proc] The primary matcher of this definition. </span> <span class='comment'># @param secondary [String|Symbol|Proc] The secondary matcher of this definition. </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>if</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>if</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>if</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>if</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>end</span> <span class='comment'># Performs a match of this definition. </span> <span class='comment'># </span> <span class='comment'># @param type [Symbol] The matcher to perform. Can be `:primary` (default) or `:secondary`. </span> <span class='comment'># @param args [Array] Arguments to pass to the matcher. The first is the definition itself. </span> <span class='comment'># @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>begin</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='op'>=</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:primary</span><span class='rparen'>)</span> <span class='kw'>rescue</span> <span class='const'>NoMethodError</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>end</span> <span class='id identifier rubyid_private'>private</span> <span class='comment'># Recognizes a browser disambiguating against another. </span> <span class='comment'># </span> <span class='comment'># @param agent [String] The agent to match. </span> <span class='comment'># @param positive_matcher [Regexp] The expression to match. </span> <span class='comment'># @param negative_matcher [Regexp] The expression NOT to match. </span> <span class='comment'># @return [Boolean] `true` if matching succeeded, `false otherwise`. </span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_disambiguate_browser'>disambiguate_browser</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span><span class='comma'>,</span> <span class='id identifier rubyid_positive_matcher'>positive_matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_negative_matcher'>negative_matcher</span><span class='rparen'>)</span> <span class='id identifier rubyid_agent'>agent</span> <span class='op'>=~</span> <span class='id identifier rubyid_positive_matcher'>positive_matcher</span> <span class='op'>&&</span> <span class='id identifier rubyid_agent'>agent</span> <span class='op'>!~</span> <span class='id identifier rubyid_negative_matcher'>negative_matcher</span> <span class='kw'>end</span> <span class='comment'># Performs a match against a target. </span> <span class='comment'># </span> <span class='comment'># @param matcher [Object] The matcher to run, can be a `Regexp`, a `Proc` or a string. </span> <span class='comment'># @param target [String] The string to match. </span> <span class='comment'># @param args [Array] Arguments to pass to the matcher. The first is definition itself. </span> <span class='comment'># @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_target'>target</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_target'>target</span><span class='rparen'>)</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:call</span><span class='rparen'>)</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_target'>target</span> <span class='op'>==</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='id identifier rubyid_target'>target</span> <span class='kw'>else</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <span id="primary=-instance_method"></span> <div class="method_details "> <h3 class="signature " id="primary-instance_method"> - (<tt>String|Symbol|Proc</tt>) <strong>primary</strong> </h3><div class="docstring"> <div class="discussion"> <p>Returns The primary matcher of this definition. Used to match browser engine, platform name and language.</p> </div> </div> <div class="tags"> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>String|Symbol|Proc</tt>)</span> — <div class='inline'><p>The primary matcher of this definition. Used to match browser engine, platform name and language.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/brauser/definition.rb', line 19</span> <span class='kw'>class</span> <span class='const'>Definition</span> <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:tag</span><span class='comma'>,</span> <span class='symbol'>:label</span><span class='comma'>,</span> <span class='symbol'>:primary</span><span class='comma'>,</span> <span class='symbol'>:secondary</span> <span class='comment'># Creates a new definition. </span> <span class='comment'># </span> <span class='comment'># @param tag [String|Symbol] An identifier for this definition. </span> <span class='comment'># @param label [String] A human readable label for this definition. </span> <span class='comment'># @param primary [String|Symbol|Proc] The primary matcher of this definition. </span> <span class='comment'># @param secondary [String|Symbol|Proc] The secondary matcher of this definition. </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>if</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>if</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>if</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>if</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>end</span> <span class='comment'># Performs a match of this definition. </span> <span class='comment'># </span> <span class='comment'># @param type [Symbol] The matcher to perform. Can be `:primary` (default) or `:secondary`. </span> <span class='comment'># @param args [Array] Arguments to pass to the matcher. The first is the definition itself. </span> <span class='comment'># @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>begin</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='op'>=</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:primary</span><span class='rparen'>)</span> <span class='kw'>rescue</span> <span class='const'>NoMethodError</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>end</span> <span class='id identifier rubyid_private'>private</span> <span class='comment'># Recognizes a browser disambiguating against another. </span> <span class='comment'># </span> <span class='comment'># @param agent [String] The agent to match. </span> <span class='comment'># @param positive_matcher [Regexp] The expression to match. </span> <span class='comment'># @param negative_matcher [Regexp] The expression NOT to match. </span> <span class='comment'># @return [Boolean] `true` if matching succeeded, `false otherwise`. </span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_disambiguate_browser'>disambiguate_browser</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span><span class='comma'>,</span> <span class='id identifier rubyid_positive_matcher'>positive_matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_negative_matcher'>negative_matcher</span><span class='rparen'>)</span> <span class='id identifier rubyid_agent'>agent</span> <span class='op'>=~</span> <span class='id identifier rubyid_positive_matcher'>positive_matcher</span> <span class='op'>&&</span> <span class='id identifier rubyid_agent'>agent</span> <span class='op'>!~</span> <span class='id identifier rubyid_negative_matcher'>negative_matcher</span> <span class='kw'>end</span> <span class='comment'># Performs a match against a target. </span> <span class='comment'># </span> <span class='comment'># @param matcher [Object] The matcher to run, can be a `Regexp`, a `Proc` or a string. </span> <span class='comment'># @param target [String] The string to match. </span> <span class='comment'># @param args [Array] Arguments to pass to the matcher. The first is definition itself. </span> <span class='comment'># @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_target'>target</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_target'>target</span><span class='rparen'>)</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:call</span><span class='rparen'>)</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_target'>target</span> <span class='op'>==</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='id identifier rubyid_target'>target</span> <span class='kw'>else</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <span id="secondary=-instance_method"></span> <div class="method_details "> <h3 class="signature " id="secondary-instance_method"> - (<tt>String|Symbol|Proc</tt>) <strong>secondary</strong> </h3><div class="docstring"> <div class="discussion"> <p>Returns The secondary matcher of this definition. Used to match browser version.</p> </div> </div> <div class="tags"> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>String|Symbol|Proc</tt>)</span> — <div class='inline'><p>The secondary matcher of this definition. Used to match browser version.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/brauser/definition.rb', line 19</span> <span class='kw'>class</span> <span class='const'>Definition</span> <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:tag</span><span class='comma'>,</span> <span class='symbol'>:label</span><span class='comma'>,</span> <span class='symbol'>:primary</span><span class='comma'>,</span> <span class='symbol'>:secondary</span> <span class='comment'># Creates a new definition. </span> <span class='comment'># </span> <span class='comment'># @param tag [String|Symbol] An identifier for this definition. </span> <span class='comment'># @param label [String] A human readable label for this definition. </span> <span class='comment'># @param primary [String|Symbol|Proc] The primary matcher of this definition. </span> <span class='comment'># @param secondary [String|Symbol|Proc] The secondary matcher of this definition. </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>if</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>if</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>if</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>if</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>end</span> <span class='comment'># Performs a match of this definition. </span> <span class='comment'># </span> <span class='comment'># @param type [Symbol] The matcher to perform. Can be `:primary` (default) or `:secondary`. </span> <span class='comment'># @param args [Array] Arguments to pass to the matcher. The first is the definition itself. </span> <span class='comment'># @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>begin</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='op'>=</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:primary</span><span class='rparen'>)</span> <span class='kw'>rescue</span> <span class='const'>NoMethodError</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>end</span> <span class='id identifier rubyid_private'>private</span> <span class='comment'># Recognizes a browser disambiguating against another. </span> <span class='comment'># </span> <span class='comment'># @param agent [String] The agent to match. </span> <span class='comment'># @param positive_matcher [Regexp] The expression to match. </span> <span class='comment'># @param negative_matcher [Regexp] The expression NOT to match. </span> <span class='comment'># @return [Boolean] `true` if matching succeeded, `false otherwise`. </span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_disambiguate_browser'>disambiguate_browser</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span><span class='comma'>,</span> <span class='id identifier rubyid_positive_matcher'>positive_matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_negative_matcher'>negative_matcher</span><span class='rparen'>)</span> <span class='id identifier rubyid_agent'>agent</span> <span class='op'>=~</span> <span class='id identifier rubyid_positive_matcher'>positive_matcher</span> <span class='op'>&&</span> <span class='id identifier rubyid_agent'>agent</span> <span class='op'>!~</span> <span class='id identifier rubyid_negative_matcher'>negative_matcher</span> <span class='kw'>end</span> <span class='comment'># Performs a match against a target. </span> <span class='comment'># </span> <span class='comment'># @param matcher [Object] The matcher to run, can be a `Regexp`, a `Proc` or a string. </span> <span class='comment'># @param target [String] The string to match. </span> <span class='comment'># @param args [Array] Arguments to pass to the matcher. The first is definition itself. </span> <span class='comment'># @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_target'>target</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_target'>target</span><span class='rparen'>)</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:call</span><span class='rparen'>)</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_target'>target</span> <span class='op'>==</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='id identifier rubyid_target'>target</span> <span class='kw'>else</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <span id="tag=-instance_method"></span> <div class="method_details "> <h3 class="signature " id="tag-instance_method"> - (<tt>String|Symbol</tt>) <strong>tag</strong> </h3><div class="docstring"> <div class="discussion"> <p>Returns An identifier for this definition.</p> </div> </div> <div class="tags"> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>String|Symbol</tt>)</span> — <div class='inline'><p>An identifier for this definition.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/brauser/definition.rb', line 19</span> <span class='kw'>class</span> <span class='const'>Definition</span> <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:tag</span><span class='comma'>,</span> <span class='symbol'>:label</span><span class='comma'>,</span> <span class='symbol'>:primary</span><span class='comma'>,</span> <span class='symbol'>:secondary</span> <span class='comment'># Creates a new definition. </span> <span class='comment'># </span> <span class='comment'># @param tag [String|Symbol] An identifier for this definition. </span> <span class='comment'># @param label [String] A human readable label for this definition. </span> <span class='comment'># @param primary [String|Symbol|Proc] The primary matcher of this definition. </span> <span class='comment'># @param secondary [String|Symbol|Proc] The secondary matcher of this definition. </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span> <span class='op'>=</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>if</span> <span class='id identifier rubyid_tag'>tag</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_label'>label</span> <span class='op'>=</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>if</span> <span class='id identifier rubyid_label'>label</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_primary'>primary</span> <span class='op'>=</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>if</span> <span class='id identifier rubyid_primary'>primary</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_secondary'>secondary</span> <span class='op'>=</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>if</span> <span class='id identifier rubyid_secondary'>secondary</span> <span class='kw'>end</span> <span class='comment'># Performs a match of this definition. </span> <span class='comment'># </span> <span class='comment'># @param type [Symbol] The matcher to perform. Can be `:primary` (default) or `:secondary`. </span> <span class='comment'># @param args [Array] Arguments to pass to the matcher. The first is the definition itself. </span> <span class='comment'># @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>begin</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='op'>=</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:primary</span><span class='rparen'>)</span> <span class='kw'>rescue</span> <span class='const'>NoMethodError</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>end</span> <span class='id identifier rubyid_private'>private</span> <span class='comment'># Recognizes a browser disambiguating against another. </span> <span class='comment'># </span> <span class='comment'># @param agent [String] The agent to match. </span> <span class='comment'># @param positive_matcher [Regexp] The expression to match. </span> <span class='comment'># @param negative_matcher [Regexp] The expression NOT to match. </span> <span class='comment'># @return [Boolean] `true` if matching succeeded, `false otherwise`. </span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_disambiguate_browser'>disambiguate_browser</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span><span class='comma'>,</span> <span class='id identifier rubyid_positive_matcher'>positive_matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_negative_matcher'>negative_matcher</span><span class='rparen'>)</span> <span class='id identifier rubyid_agent'>agent</span> <span class='op'>=~</span> <span class='id identifier rubyid_positive_matcher'>positive_matcher</span> <span class='op'>&&</span> <span class='id identifier rubyid_agent'>agent</span> <span class='op'>!~</span> <span class='id identifier rubyid_negative_matcher'>negative_matcher</span> <span class='kw'>end</span> <span class='comment'># Performs a match against a target. </span> <span class='comment'># </span> <span class='comment'># @param matcher [Object] The matcher to run, can be a `Regexp`, a `Proc` or a string. </span> <span class='comment'># @param target [String] The string to match. </span> <span class='comment'># @param args [Array] Arguments to pass to the matcher. The first is definition itself. </span> <span class='comment'># @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_target'>target</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_target'>target</span><span class='rparen'>)</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:call</span><span class='rparen'>)</span> <span class='id identifier rubyid_matcher'>matcher</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_target'>target</span> <span class='op'>==</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='id identifier rubyid_target'>target</span> <span class='kw'>else</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> </div> <div id="instance_method_details" class="method_details_list"> <h2>Instance Method Details</h2> <div class="method_details first"> <h3 class="signature first" id="match-instance_method"> - (<tt>Object|NilClass</tt>) <strong>match</strong>(type, *args) </h3><div class="docstring"> <div class="discussion"> <p>Performs a match of this definition.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>type</span> <span class='type'>(<tt>Symbol</tt>)</span> — <div class='inline'><p>The matcher to perform. Can be <code>:primary</code> (default) or <code>:secondary</code>.</p> </div> </li> <li> <span class='name'>args</span> <span class='type'>(<tt>Array</tt>)</span> — <div class='inline'><p>Arguments to pass to the matcher. The first is the definition itself.</p> </div> </li> </ul> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>Object|NilClass</tt>)</span> — <div class='inline'><p>A match if matcher succeeded, <code>nil</code> otherwise.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 40 41 42 43 44 45 46 47 48</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/brauser/definition.rb', line 40</span> <span class='kw'>def</span> <span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>begin</span> <span class='id identifier rubyid_matcher'>matcher</span> <span class='op'>=</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:primary</span><span class='rparen'>)</span> <span class='kw'>rescue</span> <span class='const'>NoMethodError</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='id identifier rubyid_perform_match'>perform_match</span><span class='lparen'>(</span><span class='id identifier rubyid_matcher'>matcher</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</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> </div> <div id="footer"> Generated on Sun May 11 14:23:59 2014 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.8.7.4 (ruby-2.1.0). </div> </body> </html>