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:
90 91 92 |
# File 'lib/kaminari/helpers/paginator.rb', line 90 def initialize(, page, last) #:nodoc: @options, @page, @last = , page, last end |
Instance Method Details
#+(other) ⇒ Object
:nodoc:
177 178 179 |
# File 'lib/kaminari/helpers/paginator.rb', line 177 def +(other) #:nodoc: to_i + other.to_i end |
#-(other) ⇒ Object
:nodoc:
181 182 183 |
# File 'lib/kaminari/helpers/paginator.rb', line 181 def -(other) #:nodoc: to_i - other.to_i end |
#<=>(other) ⇒ Object
:nodoc:
185 186 187 |
# File 'lib/kaminari/helpers/paginator.rb', line 185 def <=>(other) #:nodoc: to_i <=> other.to_i end |
#current? ⇒ Boolean
current page or not
100 101 102 |
# File 'lib/kaminari/helpers/paginator.rb', line 100 def current? @page == @options[:current_page] end |
#display_tag? ⇒ Boolean
Should we display the link tag?
165 166 167 |
# File 'lib/kaminari/helpers/paginator.rb', line 165 def display_tag? left_outer? || right_outer? || inside_window? || single_gap? end |
#first? ⇒ Boolean
the first page or not
105 106 107 |
# File 'lib/kaminari/helpers/paginator.rb', line 105 def first? @page == 1 end |
#inside_window? ⇒ Boolean
inside the inner window or not
144 145 146 |
# File 'lib/kaminari/helpers/paginator.rb', line 144 def inside_window? (@options[:current_page] - @page).abs <= @options[:window] end |
#last? ⇒ Boolean
the last page or not
110 111 112 |
# File 'lib/kaminari/helpers/paginator.rb', line 110 def last? @page == @options[:total_pages] end |
#left_outer? ⇒ Boolean
within the left outer window or not
134 135 136 |
# File 'lib/kaminari/helpers/paginator.rb', line 134 def left_outer? @page <= @options[:left] end |
#next? ⇒ Boolean
the next page or not
120 121 122 |
# File 'lib/kaminari/helpers/paginator.rb', line 120 def next? @page == @options[:current_page] + 1 end |
#number ⇒ Object
the page number
95 96 97 |
# File 'lib/kaminari/helpers/paginator.rb', line 95 def number @page end |
#out_of_range? ⇒ Boolean
The page number exceeds the range of pages or not
155 156 157 |
# File 'lib/kaminari/helpers/paginator.rb', line 155 def out_of_range? @page > @options[:total_pages] end |
#prev? ⇒ Boolean
the previous page or not
115 116 117 |
# File 'lib/kaminari/helpers/paginator.rb', line 115 def prev? @page == @options[:current_page] - 1 end |
#rel ⇒ Object
relationship with the current page
125 126 127 128 129 130 131 |
# File 'lib/kaminari/helpers/paginator.rb', line 125 def rel if next? 'next' elsif prev? 'prev' end end |
#right_outer? ⇒ Boolean
within the right outer window or not
139 140 141 |
# File 'lib/kaminari/helpers/paginator.rb', line 139 def right_outer? @options[:total_pages] - @page < @options[:right] end |
#single_gap? ⇒ Boolean
Current page is an isolated gap or not
149 150 151 152 |
# File 'lib/kaminari/helpers/paginator.rb', line 149 def single_gap? ((@page == @options[:current_page] - @options[:window] - 1) && (@page == @options[:left] + 1)) || ((@page == @options[:current_page] + @options[:window] + 1) && (@page == @options[:total_pages] - @options[:right])) end |
#to_i ⇒ Object
:nodoc:
169 170 171 |
# File 'lib/kaminari/helpers/paginator.rb', line 169 def to_i #:nodoc: number end |
#to_s ⇒ Object
:nodoc:
173 174 175 |
# File 'lib/kaminari/helpers/paginator.rb', line 173 def to_s #:nodoc: number.to_s end |
#was_truncated? ⇒ Boolean
The last rendered tag was “truncated” or not
160 161 162 |
# File 'lib/kaminari/helpers/paginator.rb', line 160 def was_truncated? @last.is_a? Gap end |