Class: Abqari::Paginator
- Inherits:
-
Object
- Object
- Abqari::Paginator
- Defined in:
- lib/abqari/paginator.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#posts ⇒ Object
readonly
Returns the value of attribute posts.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Instance Method Summary collapse
- #first? ⇒ Boolean
-
#initialize(posts:, page:, total_pages:, base_url:) ⇒ Paginator
constructor
A new instance of Paginator.
- #last? ⇒ Boolean
- #next_url ⇒ Object
- #prev_url ⇒ Object
Constructor Details
#initialize(posts:, page:, total_pages:, base_url:) ⇒ Paginator
Returns a new instance of Paginator.
7 8 9 10 11 12 |
# File 'lib/abqari/paginator.rb', line 7 def initialize(posts:, page:, total_pages:, base_url:) @posts = posts @page = page @total_pages = total_pages @base_url = base_url.sub(%r{/?\z}, '/') end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
5 6 7 |
# File 'lib/abqari/paginator.rb', line 5 def base_url @base_url end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
5 6 7 |
# File 'lib/abqari/paginator.rb', line 5 def page @page end |
#posts ⇒ Object (readonly)
Returns the value of attribute posts.
5 6 7 |
# File 'lib/abqari/paginator.rb', line 5 def posts @posts end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
5 6 7 |
# File 'lib/abqari/paginator.rb', line 5 def total_pages @total_pages end |
Instance Method Details
#first? ⇒ Boolean
14 15 16 |
# File 'lib/abqari/paginator.rb', line 14 def first? page == 1 end |
#last? ⇒ Boolean
18 19 20 |
# File 'lib/abqari/paginator.rb', line 18 def last? page == total_pages end |
#next_url ⇒ Object
29 30 31 32 33 |
# File 'lib/abqari/paginator.rb', line 29 def next_url return nil if last? "#{base_url}page/#{page + 1}/" end |
#prev_url ⇒ Object
22 23 24 25 26 27 |
# File 'lib/abqari/paginator.rb', line 22 def prev_url return nil if first? return base_url if page == 2 "#{base_url}page/#{page - 1}/" end |