Class: WillPaginate::PageNumber
- Inherits:
-
Numeric
- Object
- Numeric
- WillPaginate::PageNumber
- 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
-
#initialize(value, name) ⇒ PageNumber
constructor
A new instance of PageNumber.
- #inspect ⇒ Object
- #kind_of?(klass) ⇒ Boolean (also: #is_a?)
- #to_i ⇒ Object
- #to_offset(per_page) ⇒ Object
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
#inspect ⇒ Object
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?
40 41 42 |
# File 'lib/will_paginate/page_number.rb', line 40 def kind_of?(klass) super || to_i.kind_of?(klass) end |
#to_i ⇒ Object
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 |