Module: DataMapper::Paginator::ControlHelperAbstract
- Included in:
- DataMapper::Paginator::ControlHelper::All, DataMapper::Paginator::ControlHelper::Elastic, DataMapper::Paginator::ControlHelper::Jumping, DataMapper::Paginator::ControlHelper::Sliding
- Defined in:
- lib/dm-paginator/control/control_helper_abstract.rb
Instance Method Summary collapse
-
#normalize_page_number(page_number) ⇒ Integer
Normalize page number, brings the page number in range of the paginator.
-
#pages(page_range = nil) ⇒ Object
Get pages using a pagination style.
-
#pages_in_range(lower, upper) ⇒ Array
Return pages in range.
Instance Method Details
#normalize_page_number(page_number) ⇒ Integer
Normalize page number, brings the page number in range of the paginator.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dm-paginator/control/control_helper_abstract.rb', line 35 def normalize_page_number page_number if page_number.to_i < 1 page_number = 1 end if paginator.count > 0 && page_number > paginator.count page_number = paginator.count end page_number.to_i end |
#pages(page_range = nil) ⇒ Object
Get pages using a pagination style.
7 8 9 |
# File 'lib/dm-paginator/control/control_helper_abstract.rb', line 7 def pages page_range = nil raise NotImplementedError, "draw method not implemented" end |
#pages_in_range(lower, upper) ⇒ Array
Return pages in range.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dm-paginator/control/control_helper_abstract.rb', line 17 def pages_in_range lower, upper lower = normalize_page_number lower upper = normalize_page_number upper pages = [] ( lower ).upto( upper ) do | page_number | pages.push( page_number ) end pages end |