module NTimeLine # Pager is a class for search result summary. class Pager < Base attr_reader :total, :page, :page_count attr_accessor :request_params def initialize(doc) #:nodoc: summary = doc.root.elements["/response/result/summary"] @total = summary.elements["total"].text.to_i @page = summary.elements["page"].text.to_i @page_count = summary.elements["page_count"].text.to_i end # Goto a previous page. def prev if @page - 1 > 0 params = @request_params.merge(:page => @page - 1) request(self.class::PATH, params, self.class) end end # Goto a next page. def next if @page < @page_count params = @request_params.merge(:page => @page + 1) request(self.class::PATH, params, self.class) end end # Goto a page at the number. # n:: page number def [](n) if n > 0 && n < @page_count params = @request_params.merge(:page => n) request(self.class::PATH, params, self.class) end end alias :size :page_count end # TimelinePager is a pager of timelines search result summary. class TimeLinePager < Pager PATH = "/timelines/search" attr_reader :timelines def initialize(doc) #:nodoc: super(doc) @timelines = [] doc.root.each_element("/response/result/timelines/timeline") do |timeline| @timelines << TimeLine.new(timeline) end end end # ArticlePager is a pager of aritcles search result summary. class ArticlePager < Pager PATH = "/articles/search" attr_reader :articles def initialize(doc) #:nodoc: super(doc) @articles = [] doc.root.each_element("/response/result/articles/article") do |article| @articles << Article.new(article) end end end end