Class: OKCupid::Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/lonely_coder/search/options/paginator.rb

Overview

used to create the pagination part of a search url: low=1&count=10&ajax_load=1 where low is the start value count is the number of items per page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Paginator

Returns a new instance of Paginator.



9
10
11
12
# File 'lib/lonely_coder/search/options/paginator.rb', line 9

def initialize(options)
  @per_page = options[:per_page]
  @page = options[:page]
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



7
8
9
# File 'lib/lonely_coder/search/options/paginator.rb', line 7

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



7
8
9
# File 'lib/lonely_coder/search/options/paginator.rb', line 7

def per_page
  @per_page
end

Instance Method Details

#lowObject



14
15
16
# File 'lib/lonely_coder/search/options/paginator.rb', line 14

def low
  @low = ((@page - 1) * @per_page) + 1
end

#nextObject



18
19
20
21
# File 'lib/lonely_coder/search/options/paginator.rb', line 18

def next
  @page +=1
  self
end

#to_paramObject



23
24
25
# File 'lib/lonely_coder/search/options/paginator.rb', line 23

def to_param
  "low=#{low}&count=#{@per_page}"
end