Class: Strict::Configuration
- Inherits:
-
Object
- Object
- Strict::Configuration
- Defined in:
- lib/strict/configuration.rb
Instance Attribute Summary collapse
-
#random ⇒ Object
Returns the value of attribute random.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
Instance Method Summary collapse
-
#initialize(random: nil, sample_rate: nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #to_h ⇒ Object
- #validate? ⇒ Boolean
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
#random ⇒ Object
Returns the value of attribute random.
5 6 7 |
# File 'lib/strict/configuration.rb', line 5 def random @random end |
#sample_rate ⇒ Object
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_h ⇒ Object
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
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 |