Class: LegacyMigrations::Squirrel::Paginator

Inherits:
Array
  • Object
show all
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

Instance Method Summary collapse

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

#currentObject (readonly)

Returns the value of attribute current.



63
64
65
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63

def current
  @current
end

#current_rangeObject (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

#firstObject (readonly)

Returns the value of attribute first.



63
64
65
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



63
64
65
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63

def last
  @last
end

#nextObject (readonly)

Returns the value of attribute next.



63
64
65
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63

def next
  @next
end

#per_pageObject (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

#previousObject (readonly)

Returns the value of attribute previous.



63
64
65
# File 'lib/legacy_migrations/squirrel/paginator.rb', line 63

def previous
  @previous
end

#total_resultsObject (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