Class: RubyPx::Dataset::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_px/dataset/data.rb

Constant Summary collapse

CHUNK_SIZE =
5_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeData

Returns a new instance of Data.



8
9
10
# File 'lib/ruby_px/dataset/data.rb', line 8

def initialize
  @current_chunk_index = 0
end

Instance Attribute Details

#current_chunk_indexObject

Returns the value of attribute current_chunk_index.



6
7
8
# File 'lib/ruby_px/dataset/data.rb', line 6

def current_chunk_index
  @current_chunk_index
end

Instance Method Details

#at(index) ⇒ Object



12
13
14
15
16
17
# 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) ⇒ Object



19
20
21
22
23
24
25
26
# 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_countObject



28
29
30
# File 'lib/ruby_px/dataset/data.rb', line 28

def indexes_count
  self.current_chunk_index+1
end