Class: LHS::Pagination::Base
- Inherits:
-
Object
- Object
- LHS::Pagination::Base
- Defined in:
- lib/lhs/pagination/base.rb
Constant Summary collapse
- DEFAULT_LIMIT =
100
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#count ⇒ Object
as standard in Rails’ ActiveRecord count is not summing up, but using the number provided from data source.
- #first_page ⇒ Object
-
#initialize(data) ⇒ Base
constructor
A new instance of Base.
- #last_page ⇒ Object
- #limit ⇒ Object
- #limit_value ⇒ Object
- #next? ⇒ Boolean
- #next_offset(_step = 1) ⇒ Object
- #next_page ⇒ Object
- #offset ⇒ Object (also: #current_page, #start)
- #pages_left ⇒ Object
- #prev_page ⇒ Object
- #previous? ⇒ Boolean
- #total ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(data) ⇒ Base
Returns a new instance of Base.
10 11 12 |
# File 'lib/lhs/pagination/base.rb', line 10 def initialize(data) self.data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/lhs/pagination/base.rb', line 8 def data @data end |
Class Method Details
.page_to_offset(page, _limit) ⇒ Object
77 78 79 |
# File 'lib/lhs/pagination/base.rb', line 77 def self.page_to_offset(page, _limit) page.to_i end |
Instance Method Details
#count ⇒ Object
as standard in Rails’ ActiveRecord count is not summing up, but using the number provided from data source
15 16 17 |
# File 'lib/lhs/pagination/base.rb', line 15 def count total end |
#first_page ⇒ Object
45 46 47 |
# File 'lib/lhs/pagination/base.rb', line 45 def first_page 1 end |
#last_page ⇒ Object
49 50 51 |
# File 'lib/lhs/pagination/base.rb', line 49 def last_page total_pages end |
#limit ⇒ Object
23 24 25 |
# File 'lib/lhs/pagination/base.rb', line 23 def limit data._raw[_record.limit_key.to_sym] || DEFAULT_LIMIT end |
#limit_value ⇒ Object
69 70 71 |
# File 'lib/lhs/pagination/base.rb', line 69 def limit_value limit end |
#next? ⇒ Boolean
53 54 55 |
# File 'lib/lhs/pagination/base.rb', line 53 def next? data._raw[:next].present? end |
#next_offset(_step = 1) ⇒ Object
37 38 39 |
# File 'lib/lhs/pagination/base.rb', line 37 def next_offset(_step = 1) raise 'to be implemented in subclass' end |
#next_page ⇒ Object
65 66 67 |
# File 'lib/lhs/pagination/base.rb', line 65 def next_page current_page + 1 end |
#offset ⇒ Object Also known as: current_page, start
27 28 29 |
# File 'lib/lhs/pagination/base.rb', line 27 def offset data._raw[_record.pagination_key.to_sym].presence || 0 end |
#pages_left ⇒ Object
33 34 35 |
# File 'lib/lhs/pagination/base.rb', line 33 def pages_left total_pages - current_page end |
#prev_page ⇒ Object
61 62 63 |
# File 'lib/lhs/pagination/base.rb', line 61 def prev_page current_page - 1 end |
#previous? ⇒ Boolean
57 58 59 |
# File 'lib/lhs/pagination/base.rb', line 57 def previous? data._raw[:previous].present? end |
#total ⇒ Object
19 20 21 |
# File 'lib/lhs/pagination/base.rb', line 19 def total data._raw[_record.total_key.to_sym] end |
#total_pages ⇒ Object
73 74 75 |
# File 'lib/lhs/pagination/base.rb', line 73 def total_pages (total.to_f / limit).ceil end |