Class: SportsSouth::Chunker

Inherits:
Object
  • Object
show all
Defined in:
lib/sports_south/chunker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size, total_count = nil) ⇒ Chunker

Returns a new instance of Chunker.



6
7
8
9
10
11
# File 'lib/sports_south/chunker.rb', line 6

def initialize(size, total_count = nil)
  @size           = size
  @chunk          = Array.new
  @current_count  = 0
  @total_count    = total_count
end

Instance Attribute Details

#chunkObject

Returns the value of attribute chunk.



4
5
6
# File 'lib/sports_south/chunker.rb', line 4

def chunk
  @chunk
end

#current_countObject

Returns the value of attribute current_count.



4
5
6
# File 'lib/sports_south/chunker.rb', line 4

def current_count
  @current_count
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/sports_south/chunker.rb', line 4

def size
  @size
end

#total_countObject

Returns the value of attribute total_count.



4
5
6
# File 'lib/sports_south/chunker.rb', line 4

def total_count
  @total_count
end

Instance Method Details

#add(row) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/sports_south/chunker.rb', line 13

def add(row)
  self.reset! if is_full?

  @chunk.push(row)

  @current_count += 1
end

#is_complete?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/sports_south/chunker.rb', line 29

def is_complete?
  @total_count == @current_count
end

#is_full?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/sports_south/chunker.rb', line 25

def is_full?
  @chunk.count == @size
end

#reset!Object



21
22
23
# File 'lib/sports_south/chunker.rb', line 21

def reset!
  @chunk.clear
end