Class: ActionSet::Helpers::Paginator::PageInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/action_set/helpers/paginator.rb

Overview

Wraps a “page number” and provides some utility methods

Instance Method Summary collapse

Constructor Details

#initialize(page, info) ⇒ PageInterface

Returns a new instance of PageInterface.



116
117
118
119
# File 'lib/action_set/helpers/paginator.rb', line 116

def initialize(page, info)
  @page = page
  @info = info
end

Instance Method Details

#current?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/action_set/helpers/paginator.rb', line 125

def current?
  @page == @info[:current_page]
end

#first?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/action_set/helpers/paginator.rb', line 129

def first?
  @page == 1
end

#last?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/action_set/helpers/paginator.rb', line 133

def last?
  @page == @info[:total_pages]
end

#next?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/action_set/helpers/paginator.rb', line 141

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

#numberObject



121
122
123
# File 'lib/action_set/helpers/paginator.rb', line 121

def number
  @page
end

#out_of_range?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/action_set/helpers/paginator.rb', line 151

def out_of_range?
  @page > @info[:total_pages]
end

#prev?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/action_set/helpers/paginator.rb', line 137

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

#relObject



145
146
147
148
149
# File 'lib/action_set/helpers/paginator.rb', line 145

def rel
  return 'next' if next?
  return 'prev' if prev?
  nil
end

#to_iObject



155
156
157
# File 'lib/action_set/helpers/paginator.rb', line 155

def to_i
  number
end

#to_sObject



159
160
161
# File 'lib/action_set/helpers/paginator.rb', line 159

def to_s
  number.to_s
end