Sha256: 685cf6d4b50c2fff86414d8942ed9f7c96c9276fb76e454ee149656fe9938fe1

Contents?: true

Size: 778 Bytes

Versions: 3

Compression:

Stored size: 778 Bytes

Contents

require 'hpricot'
module GoogleCustomSearch
  class SearchResult
    def initialize result
      @result = result
    end

    def estimated_count
      (@result/"res"/"m").innerHTML.to_i
    end

    def start_index
      @result.at('res').attributes['sn'].to_i
    end

    def end_index
      @result.at('res').attributes['en'].to_i
    end

    def items
      (@result/"r").collect { |result| SearchResultItem.new result }
    end

    def range
      start_index..end_index
    end

    def first_page?
      start_index == 1
    end

    def previous_page_number
      (start_index - 1) / 10 unless first_page?
    end

    def last_page?
      end_index >= estimated_count
    end

    def next_page_number
      (end_index / 10) + 1 unless last_page?
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trusty_google_custom_search-1.0.2 lib/google_custom_search/search_result.rb
trusty_google_custom_search-1.0.1 lib/google_custom_search/search_result.rb
trusty_google_custom_search-1.0.0 lib/google_custom_search/search_result.rb