Class: Laboratory::Experiment::Variant

Inherits:
Object
  • Object
show all
Defined in:
lib/laboratory/experiment/variant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject (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_percentageObject (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

#eventsObject (readonly)

Returns the value of attribute events.



5
6
7
# File 'lib/laboratory/experiment/variant.rb', line 5

def events
  @events
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/laboratory/experiment/variant.rb', line 4

def id
  @id
end

#participant_idsObject (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

#percentageObject

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

#changesetObject



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