Sha256: c86541a05fdc7838213057339bf413a8a776cb6a4d2183dfebbc7f2234887406

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

module Hanami
  module Pagination
    class Pager
      attr_reader :pager

      def initialize(pager)
        @pager = pager
      end

      def next_page
        pager.next_page
      end

      def prev_page
        pager.prev_page
      end

      def total
        pager.total
      end

      def next_page
        pager.next_page
      end

      def current_page?(page)
        pager.current_page == page
      end

      def pages_range(delta: 3)
        first = pager.current_page - delta
        first = first > 0 ? first : 1

        last = pager.current_page + delta
        last = last < pager.total_pages ? last : pager.total_pages

        (first..last).to_a
      end

      def all_pages
        (1..pager.total_pages).to_a
      end

      def first_page?
        pager.current_page == 1
      end

      def last_page?
        pager.current_page == pager.total_pages
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-pagination-0.1.0 lib/hanami/pagination/pager.rb