Class: PagedGroups::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/paged_groups/builder.rb

Overview

This is the Public API for this library.

Constant Summary collapse

DEFAULT_PAGE_SIZE =
50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit: nil, page_size: DEFAULT_PAGE_SIZE, space: false, spacer: nil) ⇒ Builder

Returns a new instance of Builder.



22
23
24
25
26
27
28
29
# File 'lib/paged_groups/builder.rb', line 22

def initialize(limit: nil, page_size: DEFAULT_PAGE_SIZE, space: false, spacer: nil)
  @limit      = limit ? limit.to_i : nil
  @page_size  = page_size ? page_size.to_i : DEFAULT_PAGE_SIZE
  @space      = space || false
  @spacer     = spacer

  clear
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



15
16
17
# File 'lib/paged_groups/builder.rb', line 15

def limit
  @limit
end

#page_countObject (readonly)

Returns the value of attribute page_count.



15
16
17
# File 'lib/paged_groups/builder.rb', line 15

def page_count
  @page_count
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



15
16
17
# File 'lib/paged_groups/builder.rb', line 15

def page_size
  @page_size
end

#row_countObject (readonly)

Returns the value of attribute row_count.



15
16
17
# File 'lib/paged_groups/builder.rb', line 15

def row_count
  @row_count
end

#spaceObject (readonly)

Returns the value of attribute space.



15
16
17
# File 'lib/paged_groups/builder.rb', line 15

def space
  @space
end

#spacerObject (readonly)

Returns the value of attribute spacer.



15
16
17
# File 'lib/paged_groups/builder.rb', line 15

def spacer
  @spacer
end

Instance Method Details

#add(groups, force: false) ⇒ Object

Groups should be a two-dimensional array with the first dimension being the group and the second dimension being the record.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/paged_groups/builder.rb', line 33

def add(groups, force: false)
  dirty!

  groups.each do |group|
    limit_group_slice(Array(group)).each do |split_group|
      insert(split_group, force: force)
    end
  end

  self
end

#allObject Also known as: to_a



54
55
56
57
58
# File 'lib/paged_groups/builder.rb', line 54

def all
  return @all if @all

  @all = top? ? @pages : @pages + [@current_page]
end

#clearObject



45
46
47
48
49
50
51
52
# File 'lib/paged_groups/builder.rb', line 45

def clear
  dirty!

  @pages        = []
  @page_count   = 0
  @current_page = []
  @row_count    = 0
end

#to_sObject



61
62
63
# File 'lib/paged_groups/builder.rb', line 61

def to_s
  "[#{self.class.name}] Page Count: #{page_count}, Row Count: #{row_count}"
end