Class: Fidelity::PaginationHelper::Pagination

Inherits:
Object
  • Object
show all
Defined in:
app/fidelity/widgets/pagination/helpers/pagination_helper.rb

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Pagination

Returns a new instance of Pagination.



11
12
13
14
15
16
17
18
19
20
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 11

def initialize options={}
  @options = options
  @range = (options[:range] || (1..10)).to_a
  @page = options[:page] || 1
  @size = options[:size] || 7
  @next = options[:next] || true
  @offset_lenght = [0, @range.size - @size].max.to_i
  @offset_start = ((@range.size / 2) - (@offset_lenght / 2)).ceil.to_i
  @items = init_items(@offset_start, @offset_lenght)
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



10
11
12
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 10

def items
  @items
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 9

def options
  @options
end

#pageObject

Returns the value of attribute page.



9
10
11
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 9

def page
  @page
end

#rangeObject

Returns the value of attribute range.



9
10
11
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 9

def range
  @range
end

#sizeObject

Returns the value of attribute size.



9
10
11
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 9

def size
  @size
end

Instance Method Details

#back?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 22

def back?
  range.first > 1
end

#eachObject



30
31
32
33
34
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 30

def each
  @items.each do |item|
    yield item
  end
end

#next?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/fidelity/widgets/pagination/helpers/pagination_helper.rb', line 26

def next?
  @next
end