Class: SamplingHash::SamplingIO

Inherits:
Object
  • Object
show all
Defined in:
lib/sampling-hash/sampling-io.rb

Instance Method Summary collapse

Constructor Details

#initialize(io, sampler = nil) ⇒ SamplingIO

Returns a new instance of SamplingIO.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
# File 'lib/sampling-hash/sampling-io.rb', line 3

def initialize(io, sampler = nil)
  raise ArgumentError, 'first parameter should be IO' unless io.kind_of?(IO)

  @io = io
  @sampler = sampler || Sampler.new(io.stat.size)
end

Instance Method Details

#samplesObject



10
11
12
13
14
15
# File 'lib/sampling-hash/sampling-io.rb', line 10

def samples
  @sampler.each do |offset, size|
    @io.seek(offset, IO::SEEK_SET)
    yield @io.read(size)
  end
end