Sha256: 57486dd8ef79dd058159fe27fbc6277487ba00e2f34e24f06a309403bea9636d
Contents?: true
Size: 1.37 KB
Versions: 9
Compression:
Stored size: 1.37 KB
Contents
module RSolr::Ext::Response::Docs module Pageable attr_accessor :start, :per_page, :total # Returns the current page calculated from 'rows' and 'start' # WillPaginate hook def current_page return 1 if start < 1 per_page_normalized = per_page < 1 ? 1 : per_page @current_page ||= (start / per_page_normalized).ceil + 1 end # Calcuates the total pages from 'numFound' and 'rows' # WillPaginate hook def total_pages @total_pages ||= per_page > 0 ? (total / per_page.to_f).ceil : 1 end # returns the previous page number or 1 # WillPaginate hook def previous_page @previous_page ||= (current_page > 1) ? current_page - 1 : 1 end # returns the next page number or the last # WillPaginate hook def next_page @next_page ||= (current_page == total_pages) ? total_pages : current_page+1 end def has_next? current_page < total_pages end def has_previous? current_page > 1 end end def self.extended(base) d = base['response']['docs'] d.each{|doc| doc.extend RSolr::Ext::Doc } d.extend Pageable d.per_page = base['responseHeader']['params']['rows'].to_s.to_i d.start = base['response']['start'].to_s.to_i d.total = base['response']['numFound'].to_s.to_i end def docs response['docs'] end end
Version data entries
9 entries across 9 versions & 2 rubygems