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:, name: '', constraints: {}) ⇒ TargetGroup

Returns a new instance of TargetGroup.



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

def initialize(rollout:, name: '', constraints: {})
  @name = name
  @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

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
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



31
32
33
34
# File 'lib/determinator/target_group.rb', line 31

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

#humanize_percentageObject



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

def humanize_percentage
  (rollout_percent * 100).to_f.round(1)
end

#inspectObject



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

def inspect
  "<TG name:'#{name}': #{humanize_percentage}% of those matching: #{constraints}>"
end

#rollout_percentObject



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

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

#to_explain_paramsObject



27
28
29
# File 'lib/determinator/target_group.rb', line 27

def to_explain_params
  { name: name, rollout_percent: humanize_percentage }
end