Class: MailDude::Page
- Inherits:
-
Object
- Object
- MailDude::Page
- Defined in:
- lib/mail_dude/pagination.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
-
#initialize(records:, page:, per_page:, total_count:) ⇒ Page
constructor
A new instance of Page.
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #total_pages ⇒ Object
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
#page ⇒ Object (readonly)
Returns the value of attribute page.
5 6 7 |
# File 'lib/mail_dude/pagination.rb', line 5 def page @page end |
#per_page ⇒ Object (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 |
#records ⇒ Object (readonly)
Returns the value of attribute records.
5 6 7 |
# File 'lib/mail_dude/pagination.rb', line 5 def records @records end |
#total_count ⇒ Object (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_page ⇒ Object
18 19 20 |
# File 'lib/mail_dude/pagination.rb', line 18 def next_page page < total_pages ? page + 1 : nil end |
#previous_page ⇒ Object
22 23 24 |
# File 'lib/mail_dude/pagination.rb', line 22 def previous_page page > 1 ? page - 1 : nil end |
#total_pages ⇒ Object
14 15 16 |
# File 'lib/mail_dude/pagination.rb', line 14 def total_pages [(total_count.to_f / per_page).ceil, 1].max end |