Class: Determinator::TargetGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/determinator/target_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rollout:, constraints: {}) ⇒ TargetGroup

Returns a new instance of TargetGroup.



5
6
7
8
# File 'lib/determinator/target_group.rb', line 5

def initialize(rollout:, constraints: {})
  @rollout = rollout
  @constraints = constraints
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



3
4
5
# File 'lib/determinator/target_group.rb', line 3

def constraints
  @constraints
end

#rolloutObject (readonly)

Returns the value of attribute rollout.



3
4
5
# File 'lib/determinator/target_group.rb', line 3

def rollout
  @rollout
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
26
# File 'lib/determinator/target_group.rb', line 23

def ==(other)
  return false unless other.is_a?(self.class)
  other.rollout == rollout && other.constraints == constraints
end

#inspectObject



18
19
20
21
# File 'lib/determinator/target_group.rb', line 18

def inspect
  pc = (rollout_percent * 100).to_f.round(1)
  "<#{pc}% of those matching: #{constraints}>"
end

#rollout_percentObject



10
11
12
13
14
15
16
# File 'lib/determinator/target_group.rb', line 10

def rollout_percent
  # Rollout is out of 65536 because the highest rollout indicator
  # (which is a 16 bit integer) can be is 65,535. 100% rollout
  # needs to include the highest indicator, and 0% needs to not include
  # the lowest indicator.
  Rational(rollout, 65_536)
end