Class: Julewire::Core::Processing::Sampling::Head
- Inherits:
-
Object
- Object
- Julewire::Core::Processing::Sampling::Head
- Defined in:
- lib/julewire/core/processing/sampling.rb
Instance Method Summary collapse
- #call(draft) ⇒ Object
-
#initialize(rate:, key:) ⇒ Head
constructor
A new instance of Head.
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 |