Module: Flex::Struct::Paginable

Defined in:
lib/flex/struct/paginable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#total_entriesObject Also known as: total_count

Returns the value of attribute total_entries.



5
6
7
# File 'lib/flex/struct/paginable.rb', line 5

def total_entries
  @total_entries
end

#variablesObject

Returns the value of attribute variables.



5
6
7
# File 'lib/flex/struct/paginable.rb', line 5

def variables
  @variables
end

Instance Method Details

#current_pageObject



22
23
24
# File 'lib/flex/struct/paginable.rb', line 22

def current_page
  (@variables[:page] || @variables[:current_page] || 1).to_i
end

#first_page?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/flex/struct/paginable.rb', line 38

def first_page?
  current_page == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/flex/struct/paginable.rb', line 34

def last_page?
  total_pages == current_page
end

#next_pageObject



30
31
32
# File 'lib/flex/struct/paginable.rb', line 30

def next_page
  current_page < total_pages ? (current_page + 1) : nil
end

#offsetObject Also known as: offset_value



42
43
44
# File 'lib/flex/struct/paginable.rb', line 42

def offset
  per_page * (current_page - 1)
end

#out_of_bounds?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/flex/struct/paginable.rb', line 46

def out_of_bounds?
  current_page > total_pages
end

#per_pageObject Also known as: limit_value



13
14
15
16
# File 'lib/flex/struct/paginable.rb', line 13

def per_page
  (@variables[:per_page] || @variables[:limit_value] ||
      @variables[:params] && @variables[:params][:size] || 10).to_i
end

#previous_pageObject



26
27
28
# File 'lib/flex/struct/paginable.rb', line 26

def previous_page
  current_page > 1 ? (current_page - 1) : nil
end

#setup(total_entries, variables) ⇒ Object



7
8
9
10
11
# File 'lib/flex/struct/paginable.rb', line 7

def setup(total_entries, variables)
  @total_entries = total_entries
  @variables     = variables
  self
end

#total_pagesObject Also known as: num_pages



18
19
20
# File 'lib/flex/struct/paginable.rb', line 18

def total_pages
  ( @total_entries.to_f / per_page ).ceil
end