Class: Determinator::TargetGroup
- Inherits:
-
Object
- Object
- Determinator::TargetGroup
- Defined in:
- lib/determinator/target_group.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rollout ⇒ Object
readonly
Returns the value of attribute rollout.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #humanize_percentage ⇒ Object
-
#initialize(rollout:, name: '', constraints: {}) ⇒ TargetGroup
constructor
A new instance of TargetGroup.
- #inspect ⇒ Object
- #rollout_percent ⇒ Object
- #to_explain_params ⇒ Object
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
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
3 4 5 |
# File 'lib/determinator/target_group.rb', line 3 def constraints @constraints end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/determinator/target_group.rb', line 3 def name @name end |
#rollout ⇒ Object (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_percentage ⇒ Object
19 20 21 |
# File 'lib/determinator/target_group.rb', line 19 def humanize_percentage (rollout_percent * 100).to_f.round(1) end |
#inspect ⇒ Object
23 24 25 |
# File 'lib/determinator/target_group.rb', line 23 def inspect "<TG name:'#{name}': #{humanize_percentage}% of those matching: #{constraints}>" end |
#rollout_percent ⇒ Object
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_params ⇒ Object
27 28 29 |
# File 'lib/determinator/target_group.rb', line 27 def to_explain_params { name: name, rollout_percent: humanize_percentage } end |