Class: SolidErrors::ApplicationController::Page

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/solid_errors/application_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, params) ⇒ Page

Returns a new instance of Page.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/solid_errors/application_controller.rb', line 13

def initialize(collection, params)
  @count = collection.count
  @items = (params[:items] || 20).to_i
  @pages = [(@count.to_f / @items).ceil, 1].max
  @page = ((page = (params[:page] || 1).to_i) > @pages) ? @pages : page
  @first = (1 unless @page == 1)
  @last = (@pages unless @page == @pages)
  @prev = (@page - 1 unless @page == 1)
  @next = (@page == @pages) ? nil : @page + 1
  @offset = (@items * (@page - 1))
  @from = [@offset + 1, @count].min
  @to = [@offset + @items, @count].min
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def count
  @count
end

#firstObject (readonly)

Returns the value of attribute first.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def first
  @first
end

#fromObject (readonly)

Returns the value of attribute from.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def from
  @from
end

#itemsObject (readonly)

Returns the value of attribute items.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def items
  @items
end

#lastObject (readonly)

Returns the value of attribute last.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def last
  @last
end

#nextObject (readonly)

Returns the value of attribute next.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def next
  @next
end

#offsetObject (readonly)

Returns the value of attribute offset.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def offset
  @offset
end

#pagesObject (readonly)

Returns the value of attribute pages.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def pages
  @pages
end

#prevObject (readonly)

Returns the value of attribute prev.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def prev
  @prev
end

#toObject (readonly)

Returns the value of attribute to.



11
12
13
# File 'app/controllers/solid_errors/application_controller.rb', line 11

def to
  @to
end