Class: WillPaginate::PageNumber

Inherits:
Numeric
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/will_paginate/page_number.rb

Overview

integer representing a page number

Constant Summary collapse

BIGINT =

a value larger than this is not supported in SQL queries

9223372036854775807

Instance Method Summary collapse

Constructor Details

#initialize(value, name) ⇒ PageNumber

Returns a new instance of PageNumber.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/will_paginate/page_number.rb', line 14

def initialize(value, name)
  value = Integer(value)
  if 'offset' == name ? (value < 0 or value > BIGINT) : value < 1
    raise RangeError, "invalid #{name}: #{value.inspect}"
  end
  @name = name
  @value = value
rescue ArgumentError, TypeError, RangeError => error
  error.extend InvalidPage
  raise error
end

Instance Method Details

#inspectObject



32
33
34
# File 'lib/will_paginate/page_number.rb', line 32

def inspect
  "#{@name} #{to_i}"
end

#kind_of?(klass) ⇒ Boolean Also known as: is_a?

Returns:

  • (Boolean)


40
41
42
# File 'lib/will_paginate/page_number.rb', line 40

def kind_of?(klass)
  super || to_i.kind_of?(klass)
end

#to_iObject



26
27
28
# File 'lib/will_paginate/page_number.rb', line 26

def to_i
  @value
end

#to_offset(per_page) ⇒ Object



36
37
38
# File 'lib/will_paginate/page_number.rb', line 36

def to_offset(per_page)
  PageNumber.new((to_i - 1) * per_page.to_i, 'offset')
end