Class: PagedGroups::Builder
- Inherits:
-
Object
- Object
- PagedGroups::Builder
- 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
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#row_count ⇒ Object
readonly
Returns the value of attribute row_count.
-
#space ⇒ Object
readonly
Returns the value of attribute space.
-
#spacer ⇒ Object
readonly
Returns the value of attribute spacer.
Instance Method Summary collapse
-
#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.
- #all ⇒ Object (also: #to_a)
- #clear ⇒ Object
-
#initialize(limit: nil, page_size: DEFAULT_PAGE_SIZE, space: false, spacer: nil) ⇒ Builder
constructor
A new instance of Builder.
- #to_s ⇒ Object
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
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
15 16 17 |
# File 'lib/paged_groups/builder.rb', line 15 def limit @limit end |
#page_count ⇒ Object (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_size ⇒ Object (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_count ⇒ Object (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 |
#space ⇒ Object (readonly)
Returns the value of attribute space.
15 16 17 |
# File 'lib/paged_groups/builder.rb', line 15 def space @space end |
#spacer ⇒ Object (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 |
#all ⇒ Object 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 |
#clear ⇒ Object
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_s ⇒ Object
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 |