Module: DataMapper::Paginator::ControlHelperAbstract

Instance Method Summary collapse

Instance Method Details

#normalize_page_number(page_number) ⇒ Integer

Normalize page number, brings the page number in range of the paginator.

Parameters:

  • page_number (Integer)

Returns:

  • (Integer)


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.

Raises:

  • (NotImplementedError)


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.

Parameters:

  • lower (Integer)
  • upper (Integer)

Returns:

  • (Array)


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