class RubyPx::Dataset::Data

Constants

CHUNK_SIZE

Attributes

current_chunk_index[RW]

Public Class Methods

new() click to toggle source
# File lib/ruby_px/dataset/data.rb, line 8
def initialize
  @current_chunk_index = 0
end

Public Instance Methods

at(index) click to toggle source
# File lib/ruby_px/dataset/data.rb, line 12
def at index
  chunk_index = index/CHUNK_SIZE
  index_inside_chunk = index%CHUNK_SIZE

  get_chunk(chunk_index)[index_inside_chunk]
end
concat(array) click to toggle source
# File lib/ruby_px/dataset/data.rb, line 19
def concat array
  current_chunk.concat(array)
  if current_chunk.size > CHUNK_SIZE
    excess = current_chunk.pop(current_chunk.size-CHUNK_SIZE)
    self.current_chunk_index += 1
    concat(excess)
  end
end
indexes_count() click to toggle source
# File lib/ruby_px/dataset/data.rb, line 28
def indexes_count
  self.current_chunk_index+1
end

Private Instance Methods

current_chunk() click to toggle source
# File lib/ruby_px/dataset/data.rb, line 35
def current_chunk
  current = instance_variable_get("@chunk_#{self.current_chunk_index}")
  return current if current

  instance_variable_set("@chunk_#{self.current_chunk_index}", [])
end
get_chunk(chunk_index) click to toggle source
# File lib/ruby_px/dataset/data.rb, line 42
def get_chunk chunk_index
  instance_variable_get("@chunk_#{chunk_index}")
end