Class: Wor::Paginate::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wor/paginate/adapters/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, page, limit) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
# File 'lib/wor/paginate/adapters/base.rb', line 7

def initialize(content, page, limit)
  @content = content
  @page = page.to_i
  @limit = limit.to_i
  raise Wor::Paginate::Exceptions::InvalidPageNumber if @page <= 0
  raise Wor::Paginate::Exceptions::InvalidLimitNumber if @limit <= 0
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



5
6
7
# File 'lib/wor/paginate/adapters/base.rb', line 5

def page
  @page
end

Instance Method Details

#adapt?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/wor/paginate/adapters/base.rb', line 15

def adapt?
  required_methods.all? { |method| @content.respond_to? method }
end

#next_pageObject



25
26
27
28
29
# File 'lib/wor/paginate/adapters/base.rb', line 25

def next_page
  return nil if page >= total_pages

  page + 1
end

#previous_pageObject



31
32
33
34
35
# File 'lib/wor/paginate/adapters/base.rb', line 31

def previous_page
  return nil if page == 1

  page - 1
end