<?xml version="1.0" encoding="iso-8859-1"?>
<!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>
  <title>Class: Nytimes::Articles::ResultSet</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Nytimes::Articles::ResultSet</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/nytimes_articles/result_set_rb.html">
                lib/nytimes_articles/result_set.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Base.html">
                Base
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
The <a href="ResultSet.html">ResultSet</a> is returned by <a
href="Article.html#M000006">Article#search</a> and contains an array of up
to 10 results out of the total matches. For your convenience, this object
provides a selection of array methods on the underlying collection of
articles.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000012">init_from_api</a>&nbsp;&nbsp;
      <a href="#M000009">new</a>&nbsp;&nbsp;
      <a href="#M000010">page_number</a>&nbsp;&nbsp;
      <a href="#M000011">total_pages</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">BATCH_SIZE</td>
          <td>=</td>
          <td class="context-item-value">10</td>
        </tr>
        </table>
      </div>
    </div>



    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">facets</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
If you have specified a list of <tt>:facets</tt> for <a
href="Article.html#M000006">Article#search</a>, they will be returned in a
hash keyed by the facet name here.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">offset</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The offset of the result_set. Note that this is essentially the ordinal
position of the batch among all results. First 10 results are offset 0, the
next 10 are offset 1, etc.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">results</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The results array of articles returned. Note that if you call Articles#find
with :fields =&gt; :none, this will return nil even if there are matching
results.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">total_results</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The total results that matched the query.

</td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000012" class="method-detail">
        <a name="M000012"></a>

        <div class="method-heading">
          <a href="#M000012" class="method-signature">
          <span class="method-name">init_from_api</span><span class="method-args">(api_hash)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Used to initialize a <a href="ResultSet.html#M000009">new</a> result_set
from <a href="Article.html#M000006">Article#search</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000012-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nytimes_articles/result_set.rb, line 57</span>
57:                         <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">init_from_api</span>(<span class="ruby-identifier">api_hash</span>)
58:                                 <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:offset</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">integer_field</span>(<span class="ruby-identifier">api_hash</span>[<span class="ruby-value str">'offset'</span>]),
59:                                                                  <span class="ruby-identifier">:total_results</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">integer_field</span>(<span class="ruby-identifier">api_hash</span>[<span class="ruby-value str">'total'</span>]),
60:                                                                  <span class="ruby-identifier">:results</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">api_hash</span>[<span class="ruby-value str">'results'</span>].<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span> <span class="ruby-constant">Article</span>.<span class="ruby-identifier">init_from_api</span>(<span class="ruby-identifier">r</span>)},
61:                                                                  <span class="ruby-identifier">:facets</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Facet</span>.<span class="ruby-identifier">init_from_api</span>(<span class="ruby-identifier">api_hash</span>[<span class="ruby-value str">'facets'</span>])
62:                                                                 )
63:                         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(params)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nytimes_articles/result_set.rb, line 34</span>
34:                         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">params</span>)
35:                                 <span class="ruby-ivar">@offset</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:offset</span>]
36:                                 <span class="ruby-ivar">@total_results</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:total_results</span>]
37:                                 <span class="ruby-ivar">@results</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:results</span>]
38:                                 <span class="ruby-ivar">@facets</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:facets</span>]
39:                         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000010" class="method-detail">
        <a name="M000010"></a>

        <div class="method-heading">
          <a href="#M000010" class="method-signature">
          <span class="method-name">page_number</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
For your convenience, the <a href="ResultSet.html#M000010">page_number</a>
method is an alternate version of offset that counts up from 1.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000010-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nytimes_articles/result_set.rb, line 43</span>
43:                         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">page_number</span>
44:                                 <span class="ruby-keyword kw">return</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@total_results</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
45:                                 <span class="ruby-ivar">@offset</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
46:                         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">total_pages</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Calculates the total number of pages in the results based on the standard
batch size and total results.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nytimes_articles/result_set.rb, line 50</span>
50:                         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">total_pages</span>
51:                                 <span class="ruby-keyword kw">return</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@total_results</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
52:                                 (<span class="ruby-ivar">@total_results</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-constant">BATCH_SIZE</span>).<span class="ruby-identifier">ceil</span>
53:                         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>