class Nokotime::Paginator

Attributes

Public Class Methods

new(raw_links) click to toggle source
# File lib/nokotime/paginator.rb, line 5
def initialize(raw_links)
  @raw_links = raw_links
end

Public Instance Methods

first() click to toggle source
# File lib/nokotime/paginator.rb, line 17
def first
  find("first")&.dig(:url)
end
last() click to toggle source
# File lib/nokotime/paginator.rb, line 21
def last
  find("last")&.dig(:url)
end
next() click to toggle source
# File lib/nokotime/paginator.rb, line 9
def next
  find("next")&.dig(:url)
end
prev() click to toggle source
# File lib/nokotime/paginator.rb, line 13
def prev
  find("prev")&.dig(:url)
end
total_pages() click to toggle source
# File lib/nokotime/paginator.rb, line 25
def total_pages
  find("last")&.dig(:number_page)
end

Private Instance Methods

find(rel) click to toggle source
# File lib/nokotime/paginator.rb, line 31
def find(rel)
  pages.find { |page| page[:rel] == rel }
end
pages() click to toggle source
# File lib/nokotime/paginator.rb, line 35
def pages
  return {} if raw_links.empty?

  @pages ||=
    raw_links.split(",").map do |link|
      url, rel, number_page = split_and_clean_link(link)

      {
        url: "#{url.path}?#{url.query}",
        rel: rel,
        number_page: number_page
      }
    end
end