Created
August 19, 2021 19:34
-
-
Save shqear93/17957824532f057388aa3ce05bab2f58 to your computer and use it in GitHub Desktop.
Pagination list algorithm for ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pagination_list | |
range = (0..maximum_pages_number).to_a | |
adjacent = (@pages_in_bar / 2).floor * 2 + 1 | |
range[[0, [range.size - 1 - adjacent, page_number.to_i - (adjacent / 2).ceil].min].max, adjacent] if adjacent >= 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment