Class: Strict::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/strict/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(random: nil, sample_rate: nil) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
10
# File 'lib/strict/configuration.rb', line 7

def initialize(random: nil, sample_rate: nil)
  self.random = random || Random.new
  self.sample_rate = sample_rate || 1
end

Instance Attribute Details

#randomObject

Returns the value of attribute random.



5
6
7
# File 'lib/strict/configuration.rb', line 5

def random
  @random
end

#sample_rateObject

Returns the value of attribute sample_rate.



5
6
7
# File 'lib/strict/configuration.rb', line 5

def sample_rate
  @sample_rate
end

Instance Method Details

#to_hObject



37
38
39
40
41
42
# File 'lib/strict/configuration.rb', line 37

def to_h
  {
    random: random,
    sample_rate: sample_rate
  }
end

#validate?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/strict/configuration.rb', line 33

def validate?
  sample_rate >= 1 || (sample_rate > 0 && random.rand < sample_rate) # rubocop:disable Style/NumericPredicate
end