Class: PostgresqlWeb::Paginator
- Inherits:
-
Object
- Object
- PostgresqlWeb::Paginator
- Defined in:
- lib/postgresql_web/paginator.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_records ⇒ Object
readonly
Returns the value of attribute total_records.
Instance Method Summary collapse
- #first_page? ⇒ Boolean
-
#initialize(data, page, per_page, total_records) ⇒ Paginator
constructor
A new instance of Paginator.
- #last_page? ⇒ Boolean
- #offset ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(data, page, per_page, total_records) ⇒ Paginator
Returns a new instance of Paginator.
5 6 7 8 9 10 |
# File 'lib/postgresql_web/paginator.rb', line 5 def initialize(data, page, per_page, total_records) @data = data @page = page.to_i @per_page = per_page.to_i @total_records = total_records.to_i end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/postgresql_web/paginator.rb', line 3 def data @data end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
3 4 5 |
# File 'lib/postgresql_web/paginator.rb', line 3 def page @page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
3 4 5 |
# File 'lib/postgresql_web/paginator.rb', line 3 def per_page @per_page end |
#total_records ⇒ Object (readonly)
Returns the value of attribute total_records.
3 4 5 |
# File 'lib/postgresql_web/paginator.rb', line 3 def total_records @total_records end |
Instance Method Details
#first_page? ⇒ Boolean
28 29 30 |
# File 'lib/postgresql_web/paginator.rb', line 28 def first_page? page.to_i <= 1 end |
#last_page? ⇒ Boolean
31 32 33 |
# File 'lib/postgresql_web/paginator.rb', line 31 def last_page? page == total_pages end |
#offset ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/postgresql_web/paginator.rb', line 12 def offset if page > 0 self.per_page * ( page - 1) else 0 end end |
#total_pages ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/postgresql_web/paginator.rb', line 20 def total_pages if self.total_records > 0 (self.total_records.to_f / self.per_page).ceil else 1 end end |