Class: LegacyMigrations::Squirrel::Paginator
- Inherits:
-
Array
- Object
- Array
- LegacyMigrations::Squirrel::Paginator
- Defined in:
- lib/legacy_migrations/squirrel/paginator.rb
Overview
A Paginator object is what gets inserted into the result set and is returned by the #pages method of the result set. Contains offets and limits for all pages.
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#current_range ⇒ Object
readonly
Returns the value of attribute current_range.
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#next ⇒ Object
readonly
Returns the value of attribute next.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
-
#total_results ⇒ Object
readonly
Returns the value of attribute total_results.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Paginator
constructor
A new instance of Paginator.
Constructor Details
#initialize(opts = {}) ⇒ Paginator
Returns a new instance of Paginator.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 64 def initialize opts={} @total_results = opts[:count].to_i @limit = opts[:limit].to_i @offset = opts[:offset].to_i @per_page = @limit @current = (@offset / @limit) + 1 @first = 1 @last = ((@total_results-1) / @limit) + 1 @next = @current + 1 if @current < @last @previous = @current - 1 if @current > 1 @current_range = ((@offset+1)..([@offset+@limit, @total_results].min)) (@first..@last).each do |page| self[page-1] = Page.new((page-1) * @per_page, @per_page, page, @per_page) end end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
63 64 65 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63 def current @current end |
#current_range ⇒ Object (readonly)
Returns the value of attribute current_range.
63 64 65 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63 def current_range @current_range end |
#first ⇒ Object (readonly)
Returns the value of attribute first.
63 64 65 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
63 64 65 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63 def last @last end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
63 64 65 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63 def next @next end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
63 64 65 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63 def per_page @per_page end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
63 64 65 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63 def previous @previous end |
#total_results ⇒ Object (readonly)
Returns the value of attribute total_results.
63 64 65 |
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63 def total_results @total_results end |