Class: GearedPagination::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/geared_pagination/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, from:) ⇒ Page

Returns a new instance of Page.



7
8
9
10
# File 'lib/geared_pagination/page.rb', line 7

def initialize(number, from:)
  @number, @collection = number, from
  @portion = GearedPagination::Portion.new(page_number: number, per_page: from.ratios)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'lib/geared_pagination/page.rb', line 5

def collection
  @collection
end

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/geared_pagination/page.rb', line 5

def number
  @number
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/geared_pagination/page.rb', line 21

def empty?
  records.load.none?
end

#first?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/geared_pagination/page.rb', line 26

def first?
  number == 1
end

#last?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/geared_pagination/page.rb', line 34

def last?
  number == collection.page_count
end

#next_numberObject



39
40
41
# File 'lib/geared_pagination/page.rb', line 39

def next_number
  number + 1
end

#only?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/geared_pagination/page.rb', line 30

def only?
  collection.page_count == 1
end

#recordsObject



12
13
14
# File 'lib/geared_pagination/page.rb', line 12

def records
  @records ||= @portion.from(collection.records)
end

#used?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/geared_pagination/page.rb', line 17

def used?
  records.load.any?
end