Class: Kaminari::Helpers::Paginator::PageProxy
- Inherits:
-
Object
- Object
- Kaminari::Helpers::Paginator::PageProxy
- Includes:
- Comparable
- Defined in:
- lib/kaminari/helpers/paginator.rb
Overview
Wraps a “page number” and provides some utility methods
Instance Method Summary collapse
-
#+(other) ⇒ Object
:nodoc:.
-
#-(other) ⇒ Object
:nodoc:.
-
#<=>(other) ⇒ Object
:nodoc:.
-
#current? ⇒ Boolean
current page or not.
-
#display_tag? ⇒ Boolean
Should we display the link tag?.
-
#first? ⇒ Boolean
the first page or not.
-
#initialize(options, page, last) ⇒ PageProxy
constructor
:nodoc:.
-
#inside_window? ⇒ Boolean
inside the inner window or not.
-
#last? ⇒ Boolean
the last page or not.
-
#left_outer? ⇒ Boolean
within the left outer window or not.
-
#next? ⇒ Boolean
the next page or not.
-
#number ⇒ Object
the page number.
-
#out_of_range? ⇒ Boolean
The page number exceeds the range of pages or not.
-
#prev? ⇒ Boolean
the previous page or not.
-
#rel ⇒ Object
relationship with the current page.
-
#right_outer? ⇒ Boolean
within the right outer window or not.
-
#single_gap? ⇒ Boolean
Current page is an isolated gap or not.
-
#to_i ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
:nodoc:.
-
#was_truncated? ⇒ Boolean
The last rendered tag was “truncated” or not.
Constructor Details
#initialize(options, page, last) ⇒ PageProxy
:nodoc:
88 89 90 |
# File 'lib/kaminari/helpers/paginator.rb', line 88 def initialize(, page, last) #:nodoc: , @page, @last = , page, last end |
Instance Method Details
#+(other) ⇒ Object
:nodoc:
175 176 177 |
# File 'lib/kaminari/helpers/paginator.rb', line 175 def +(other) #:nodoc: to_i + other.to_i end |
#-(other) ⇒ Object
:nodoc:
179 180 181 |
# File 'lib/kaminari/helpers/paginator.rb', line 179 def -(other) #:nodoc: to_i - other.to_i end |
#<=>(other) ⇒ Object
:nodoc:
183 184 185 |
# File 'lib/kaminari/helpers/paginator.rb', line 183 def <=>(other) #:nodoc: to_i <=> other.to_i end |
#current? ⇒ Boolean
current page or not
98 99 100 |
# File 'lib/kaminari/helpers/paginator.rb', line 98 def current? @page == [:current_page] end |
#display_tag? ⇒ Boolean
Should we display the link tag?
163 164 165 |
# File 'lib/kaminari/helpers/paginator.rb', line 163 def display_tag? left_outer? || right_outer? || inside_window? || single_gap? end |
#first? ⇒ Boolean
the first page or not
103 104 105 |
# File 'lib/kaminari/helpers/paginator.rb', line 103 def first? @page == 1 end |
#inside_window? ⇒ Boolean
inside the inner window or not
142 143 144 |
# File 'lib/kaminari/helpers/paginator.rb', line 142 def inside_window? ([:current_page] - @page).abs <= [:window] end |
#last? ⇒ Boolean
the last page or not
108 109 110 |
# File 'lib/kaminari/helpers/paginator.rb', line 108 def last? @page == [:total_pages] end |
#left_outer? ⇒ Boolean
within the left outer window or not
132 133 134 |
# File 'lib/kaminari/helpers/paginator.rb', line 132 def left_outer? @page <= [:left] end |
#next? ⇒ Boolean
the next page or not
118 119 120 |
# File 'lib/kaminari/helpers/paginator.rb', line 118 def next? @page == [:current_page] + 1 end |
#number ⇒ Object
the page number
93 94 95 |
# File 'lib/kaminari/helpers/paginator.rb', line 93 def number @page end |
#out_of_range? ⇒ Boolean
The page number exceeds the range of pages or not
153 154 155 |
# File 'lib/kaminari/helpers/paginator.rb', line 153 def out_of_range? @page > [:total_pages] end |
#prev? ⇒ Boolean
the previous page or not
113 114 115 |
# File 'lib/kaminari/helpers/paginator.rb', line 113 def prev? @page == [:current_page] - 1 end |
#rel ⇒ Object
relationship with the current page
123 124 125 126 127 128 129 |
# File 'lib/kaminari/helpers/paginator.rb', line 123 def rel if next? 'next' elsif prev? 'prev' end end |
#right_outer? ⇒ Boolean
within the right outer window or not
137 138 139 |
# File 'lib/kaminari/helpers/paginator.rb', line 137 def right_outer? [:total_pages] - @page < [:right] end |
#single_gap? ⇒ Boolean
Current page is an isolated gap or not
147 148 149 150 |
# File 'lib/kaminari/helpers/paginator.rb', line 147 def single_gap? ((@page == [:current_page] - [:window] - 1) && (@page == [:left] + 1)) || ((@page == [:current_page] + [:window] + 1) && (@page == [:total_pages] - [:right])) end |
#to_i ⇒ Object
:nodoc:
167 168 169 |
# File 'lib/kaminari/helpers/paginator.rb', line 167 def to_i #:nodoc: number end |
#to_s ⇒ Object
:nodoc:
171 172 173 |
# File 'lib/kaminari/helpers/paginator.rb', line 171 def to_s #:nodoc: number.to_s end |
#was_truncated? ⇒ Boolean
The last rendered tag was “truncated” or not
158 159 160 |
# File 'lib/kaminari/helpers/paginator.rb', line 158 def was_truncated? @last.is_a? Gap end |