Class: MailDude::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_dude/pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records:, page:, per_page:, total_count:) ⇒ Page

Returns a new instance of Page.



7
8
9
10
11
12
# File 'lib/mail_dude/pagination.rb', line 7

def initialize(records:, page:, per_page:, total_count:)
  @records = records
  @page = normalize_positive(page, 1)
  @per_page = normalize_positive(per_page, MailDude.configuration.default_per_page)
  @total_count = total_count.to_i
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



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

def per_page
  @per_page
end

#recordsObject (readonly)

Returns the value of attribute records.



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

def records
  @records
end

#total_countObject (readonly)

Returns the value of attribute total_count.



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

def total_count
  @total_count
end

Instance Method Details

#next_pageObject



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

def next_page
  page < total_pages ? page + 1 : nil
end

#previous_pageObject



22
23
24
# File 'lib/mail_dude/pagination.rb', line 22

def previous_page
  page > 1 ? page - 1 : nil
end

#total_pagesObject



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

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