Class: Laboratory::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:) ⇒ User

Returns a new instance of User.



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

def initialize(id:)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/laboratory/user.rb', line 3

def id
  @id
end

Instance Method Details

#experimentsObject



9
10
11
12
13
14
15
# File 'lib/laboratory/user.rb', line 9

def experiments
  Experiment.all.select do |experiment|
    experiment.variants.any? do |variant|
      variant.participant_ids.include?(id)
    end
  end
end

#variant_for_experiment(experiment) ⇒ Object



17
18
19
20
21
# File 'lib/laboratory/user.rb', line 17

def variant_for_experiment(experiment)
  experiment.variants.find do |variant|
    variant.participant_ids.include?(id)
  end
end