Class: PageClip

Inherits:
Object
  • Object
show all
Defined in:
lib/page_clip.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_count, per_page, current_page, pages_to_show_count) ⇒ PageClip

Returns a new instance of PageClip.



4
5
6
7
8
9
10
11
# File 'lib/page_clip.rb', line 4

def initialize(item_count, per_page, current_page, pages_to_show_count)
  verify_arguments(item_count, per_page, current_page, pages_to_show_count)

  @current_page = current_page
  @page_count = (item_count.to_f / per_page.to_f).ceil
  @pages = (1..@page_count).to_set
  @side_pages_to_show_count = (pages_to_show_count - 1) / 2
end

Class Method Details

.show(item_count:, per_page:, current_page:, pages_to_show_count:) ⇒ Object



13
14
15
# File 'lib/page_clip.rb', line 13

def self.show(item_count:, per_page:, current_page:, pages_to_show_count:)
  new(item_count, per_page, current_page, pages_to_show_count).calculate
end

Instance Method Details

#calculateObject



17
18
19
# File 'lib/page_clip.rb', line 17

def calculate
  [pages_to_show, @page_count]
end