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:



90
91
92
# File 'lib/kaminari/helpers/paginator.rb', line 90

def initialize(options, page, last) #:nodoc:
  @options, @page, @last = options, 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

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


120
121
122
# File 'lib/kaminari/helpers/paginator.rb', line 120

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

#numberObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


115
116
117
# File 'lib/kaminari/helpers/paginator.rb', line 115

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

#relObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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_iObject

:nodoc:



169
170
171
# File 'lib/kaminari/helpers/paginator.rb', line 169

def to_i #:nodoc:
  number
end

#to_sObject

: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

Returns:

  • (Boolean)


160
161
162
# File 'lib/kaminari/helpers/paginator.rb', line 160

def was_truncated?
  @last.is_a? Gap
end