Class: Laboratory::Experiment::Variant
- Inherits:
-
Object
- Object
- Laboratory::Experiment::Variant
- Defined in:
- lib/laboratory/experiment/variant.rb
Instance Attribute Summary collapse
-
#_original_id ⇒ Object
readonly
Returns the value of attribute _original_id.
-
#_original_percentage ⇒ Object
readonly
Returns the value of attribute _original_percentage.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#id ⇒ Object
Returns the value of attribute id.
-
#participant_ids ⇒ Object
readonly
Returns the value of attribute participant_ids.
-
#percentage ⇒ Object
Returns the value of attribute percentage.
Instance Method Summary collapse
- #add_participant(user) ⇒ Object
- #changeset ⇒ Object
-
#initialize(id:, percentage:, participant_ids: [], events: []) ⇒ Variant
constructor
A new instance of Variant.
Constructor Details
#initialize(id:, percentage:, participant_ids: [], events: []) ⇒ Variant
Returns a new instance of Variant.
12 13 14 15 16 17 18 19 20 |
# File 'lib/laboratory/experiment/variant.rb', line 12 def initialize(id:, percentage:, participant_ids: [], events: []) @id = id @percentage = percentage @participant_ids = participant_ids @events = events @_original_id = id @_original_percentage = percentage end |
Instance Attribute Details
#_original_id ⇒ Object (readonly)
Returns the value of attribute _original_id.
5 6 7 |
# File 'lib/laboratory/experiment/variant.rb', line 5 def _original_id @_original_id end |
#_original_percentage ⇒ Object (readonly)
Returns the value of attribute _original_percentage.
5 6 7 |
# File 'lib/laboratory/experiment/variant.rb', line 5 def _original_percentage @_original_percentage end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
5 6 7 |
# File 'lib/laboratory/experiment/variant.rb', line 5 def events @events end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/laboratory/experiment/variant.rb', line 4 def id @id end |
#participant_ids ⇒ Object (readonly)
Returns the value of attribute participant_ids.
5 6 7 |
# File 'lib/laboratory/experiment/variant.rb', line 5 def participant_ids @participant_ids end |
#percentage ⇒ Object
Returns the value of attribute percentage.
4 5 6 |
# File 'lib/laboratory/experiment/variant.rb', line 4 def percentage @percentage end |
Instance Method Details
#add_participant(user) ⇒ Object
22 23 24 |
# File 'lib/laboratory/experiment/variant.rb', line 22 def add_participant(user) participant_ids << user.id end |
#changeset ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/laboratory/experiment/variant.rb', line 26 def changeset set = {} set[:id] = [_original_id, id] if _original_id != id if _original_percentage != percentage set[:percentage] = [_original_percentage, percentage] end set end |