Class: SamplingHash::SamplingIO
- Inherits:
-
Object
- Object
- SamplingHash::SamplingIO
- Defined in:
- lib/sampling-hash/sampling-io.rb
Instance Method Summary collapse
-
#initialize(io, sampler = nil) ⇒ SamplingIO
constructor
A new instance of SamplingIO.
- #samples ⇒ Object
Constructor Details
#initialize(io, sampler = nil) ⇒ SamplingIO
Returns a new instance of SamplingIO.
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
#samples ⇒ Object
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 |