module Elastics::Struct::Paginable

Attributes

total_count[RW]
total_entries[RW]
variables[RW]

Public Instance Methods

current_page() click to toggle source
# File lib/elastics/struct/paginable.rb, line 22
def current_page
  (@variables[:page] || @variables[:current_page] || 1).to_i
end
first_page?() click to toggle source
# File lib/elastics/struct/paginable.rb, line 38
def first_page?
  current_page == 1
end
last_page?() click to toggle source
# File lib/elastics/struct/paginable.rb, line 34
def last_page?
  total_pages == current_page
end
limit_value()
Alias for: per_page
next_page() click to toggle source
# File lib/elastics/struct/paginable.rb, line 30
def next_page
  current_page < total_pages ? (current_page + 1) : nil
end
num_pages()
Alias for: total_pages
offset() click to toggle source
# File lib/elastics/struct/paginable.rb, line 42
def offset
  per_page * (current_page - 1)
end
Also aliased as: offset_value
offset_value()
Alias for: offset
out_of_bounds?() click to toggle source
# File lib/elastics/struct/paginable.rb, line 46
def out_of_bounds?
  current_page > total_pages
end
per_page() click to toggle source
# File lib/elastics/struct/paginable.rb, line 13
def per_page
  (@variables[:per_page] || @variables[:limit_value] ||
      @variables[:params] && @variables[:params][:size] || 10).to_i
end
Also aliased as: limit_value
previous_page() click to toggle source
# File lib/elastics/struct/paginable.rb, line 26
def previous_page
  current_page > 1 ? (current_page - 1) : nil
end
setup(total_entries, variables) click to toggle source
# File lib/elastics/struct/paginable.rb, line 7
def setup(total_entries, variables)
  @total_entries = total_entries
  @variables     = variables
  self
end
total_pages() click to toggle source
# File lib/elastics/struct/paginable.rb, line 18
def total_pages
  ( @total_entries.to_f / per_page ).ceil
end
Also aliased as: num_pages