Sha256: 584086559fe1796a128a704bcde4c92644d711e4622973c79f7cb06160ebf53a

Contents?: true

Size: 683 Bytes

Versions: 16

Compression:

Stored size: 683 Bytes

Contents

class SampleSkimmer
  def initialize(num_sample_rows, &callback)
    @num_sample_rows = num_sample_rows
    @callback = callback
    @samples = []
    @callback_called = false
  end

  def callbacks
    { during_execute: collect_samples, after_execute: submit_data_if_unsubmitted }
  end

  private

  def collect_samples
    lambda do |row, row_count|
      if row_count <= @num_sample_rows
        @samples << row
        if row_count == @num_sample_rows
          @callback.call(@samples)
          @callback_called = true
        end
      end
    end      
  end

  def submit_data_if_unsubmitted
    ->(row_count) { @callback.call(@samples) unless @callback_called }
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev lib/sample_skimmer.rb
aleph_analytics-0.4.8 lib/sample_skimmer.rb
aleph_analytics-0.4.7 lib/sample_skimmer.rb
aleph_analytics-0.4.4 lib/sample_skimmer.rb
aleph_analytics-0.4.2 lib/sample_skimmer.rb
aleph_analytics-0.4.1 lib/sample_skimmer.rb
aleph_analytics-0.3.0 lib/sample_skimmer.rb
aleph_analytics-0.2.0 lib/sample_skimmer.rb
aleph_analytics-0.1.0 lib/sample_skimmer.rb
aleph_analytics-0.0.6 lib/sample_skimmer.rb
aleph_analytics-0.0.5 lib/sample_skimmer.rb
aleph_analytics-0.0.4 lib/sample_skimmer.rb
aleph_analytics-0.0.3 lib/sample_skimmer.rb
aleph_analytics-0.0.2 lib/sample_skimmer.rb
aleph_analytics-0.0.1.alpha lib/sample_skimmer.rb
aleph_analytics-0.0.0.alpha lib/sample_skimmer.rb