Class: Kaminari::Helpers::Paginator::PageProxy

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/kaminari/helpers/paginator.rb

Overview

Wraps a “page number” and provides some utility methods

Instance Method Summary collapse

Constructor Details

#initialize(options, page, last) ⇒ PageProxy

:nodoc:



88
89
90
# File 'lib/kaminari/helpers/paginator.rb', line 88

def initialize(options, page, last) #:nodoc:
  @options, @page, @last = options, 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 == @options[: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?
  (@options[:current_page] - @page).abs <= @options[:window]
end

#last?Boolean

the last page or not



108
109
110
# File 'lib/kaminari/helpers/paginator.rb', line 108

def last?
  @page == @options[: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 <= @options[:left]
end

#next?Boolean

the next page or not



118
119
120
# File 'lib/kaminari/helpers/paginator.rb', line 118

def next?
  @page == @options[:current_page] + 1
end

#numberObject

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 > @options[:total_pages]
end

#prev?Boolean

the previous page or not



113
114
115
# File 'lib/kaminari/helpers/paginator.rb', line 113

def prev?
  @page == @options[:current_page] - 1
end

#relObject

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?
  @options[:total_pages] - @page < @options[: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 == @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_iObject

:nodoc:



167
168
169
# File 'lib/kaminari/helpers/paginator.rb', line 167

def to_i #:nodoc:
  number
end

#to_sObject

: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