Class: WillPaginate::PageNumber

Inherits:
Integer
  • 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.


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

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
  super(value)
rescue ArgumentError, TypeError, RangeError => error
  error.extend InvalidPage
  raise error
end

Instance Method Details

#inspectObject


29
30
31
# File 'lib/will_paginate/page_number.rb', line 29

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

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

Returns:

  • (Boolean)

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

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

#to_offset(per_page) ⇒ Object


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

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