Class: Super::Pagination
- Inherits:
-
Object
- Object
- Super::Pagination
- Includes:
- Enumerable
- Defined in:
- lib/super/pagination.rb
Instance Attribute Summary collapse
-
#current_pageno ⇒ Object
Returns the value of attribute current_pageno.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(total_count:, limit:, query_params:, page_query_param:) ⇒ Pagination
constructor
A new instance of Pagination.
- #necessary? ⇒ Boolean
- #offset ⇒ Object
Constructor Details
#initialize(total_count:, limit:, query_params:, page_query_param:) ⇒ Pagination
Returns a new instance of Pagination.
8 9 10 11 12 13 14 15 |
# File 'lib/super/pagination.rb', line 8 def initialize(total_count:, limit:, query_params:, page_query_param:) @total_count = total_count.to_i @limit = limit.to_i @query_params = query_params @page_query_param = page_query_param self.current_pageno = query_params[page_query_param] end |
Instance Attribute Details
#current_pageno ⇒ Object
Returns the value of attribute current_pageno.
5 6 7 |
# File 'lib/super/pagination.rb', line 5 def current_pageno @current_pageno end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
6 7 8 |
# File 'lib/super/pagination.rb', line 6 def limit @limit end |
Instance Method Details
#each ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/super/pagination.rb', line 36 def each if !block_given? return enum_for(:each) end (1..pages).each do |pageno| is_current_page = pageno == current_pageno display = pageno.to_s page_query_params = @query_params.dup if pageno == 1 page_query_params.delete(:page) else page_query_params[@page_query_param] = pageno end yield(page_query_params, is_current_page, display) end end |
#necessary? ⇒ Boolean
32 33 34 |
# File 'lib/super/pagination.rb', line 32 def necessary? pages > 1 end |
#offset ⇒ Object
17 18 19 |
# File 'lib/super/pagination.rb', line 17 def offset limit * (current_pageno - 1) end |