Class: Julewire::Core::Processing::Sampling::Head

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/core/processing/sampling.rb

Instance Method Summary collapse

Constructor Details

#initialize(rate:, key:) ⇒ Head

Returns a new instance of Head.



67
68
69
70
71
# File 'lib/julewire/core/processing/sampling.rb', line 67

def initialize(rate:, key:)
  @threshold = Sampling.threshold_for(rate)
  @key = key
  Validation.validate_callable!(key, name: :key, allow_nil: true)
end

Instance Method Details

#call(draft) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/julewire/core/processing/sampling.rb', line 73

def call(draft)
  return :drop if @threshold.zero?

  value = key_for(draft)
  return :drop if value.nil?
  return if @threshold == HASH_SPACE

  Sampling.stable_hash(value) < @threshold ? nil : :drop
end