Class: SourceMonitor::Pagination::Result

Inherits:
Struct
  • Object
show all
Defined in:
lib/source_monitor/pagination/paginator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#has_next_pageObject

Returns the value of attribute has_next_page

Returns:

  • (Object)

    the current value of has_next_page



5
6
7
# File 'lib/source_monitor/pagination/paginator.rb', line 5

def has_next_page
  @has_next_page
end

#has_previous_pageObject

Returns the value of attribute has_previous_page

Returns:

  • (Object)

    the current value of has_previous_page



5
6
7
# File 'lib/source_monitor/pagination/paginator.rb', line 5

def has_previous_page
  @has_previous_page
end

#pageObject

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page



5
6
7
# File 'lib/source_monitor/pagination/paginator.rb', line 5

def page
  @page
end

#per_pageObject

Returns the value of attribute per_page

Returns:

  • (Object)

    the current value of per_page



5
6
7
# File 'lib/source_monitor/pagination/paginator.rb', line 5

def per_page
  @per_page
end

#recordsObject

Returns the value of attribute records

Returns:

  • (Object)

    the current value of records



5
6
7
# File 'lib/source_monitor/pagination/paginator.rb', line 5

def records
  @records
end

#total_countObject

Returns the value of attribute total_count

Returns:

  • (Object)

    the current value of total_count



5
6
7
# File 'lib/source_monitor/pagination/paginator.rb', line 5

def total_count
  @total_count
end

Instance Method Details

#has_next_page?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/source_monitor/pagination/paginator.rb', line 14

def has_next_page?
  !!has_next_page
end

#has_previous_page?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/source_monitor/pagination/paginator.rb', line 18

def has_previous_page?
  !!has_previous_page
end

#next_pageObject



22
23
24
25
26
# File 'lib/source_monitor/pagination/paginator.rb', line 22

def next_page
  return nil unless has_next_page

  page + 1
end

#previous_pageObject



28
29
30
31
32
# File 'lib/source_monitor/pagination/paginator.rb', line 28

def previous_page
  return nil unless has_previous_page

  [ page - 1, 1 ].max
end

#total_pagesObject



34
35
36
37
38
# File 'lib/source_monitor/pagination/paginator.rb', line 34

def total_pages
  return 1 if total_count.nil? || total_count <= 0

  [ 1, (total_count.to_f / per_page).ceil ].max
end