Class: Verdict::Assignment

Inherits:
Object
  • Object
show all
Defined in:
lib/verdict/assignment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(experiment, subject, group, originally_created_at, temporary = false) ⇒ Assignment

Returns a new instance of Assignment.



4
5
6
7
8
9
10
11
# File 'lib/verdict/assignment.rb', line 4

def initialize(experiment, subject, group, originally_created_at, temporary = false)
  @experiment         = experiment
  @subject            = subject
  @group              = group
  @first              = originally_created_at.nil? || experiment.manual_assignment_timestamps?
  @created_at         = originally_created_at || Time.now.utc
  @temporary          = temporary
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



2
3
4
# File 'lib/verdict/assignment.rb', line 2

def created_at
  @created_at
end

#experimentObject (readonly)

Returns the value of attribute experiment.



2
3
4
# File 'lib/verdict/assignment.rb', line 2

def experiment
  @experiment
end

#groupObject (readonly)

Returns the value of attribute group.



2
3
4
# File 'lib/verdict/assignment.rb', line 2

def group
  @group
end

#subjectObject (readonly)

Returns the value of attribute subject.



2
3
4
# File 'lib/verdict/assignment.rb', line 2

def subject
  @subject
end

Instance Method Details

#===(other) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/verdict/assignment.rb', line 60

def ===(other)
  case other
    when nil; !qualified?
    when Verdict::Assignment; other.group === group
    when Verdict::Group; other === group
    when Symbol, String; qualified? ? group.handle == other.to_s : false
    else false
  end
end

#as_json(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/verdict/assignment.rb', line 45

def as_json(options = {})
  {
    experiment: experiment.handle,
    subject:    subject_identifier,
    qualified:  qualified?,
    returning:  returning?,
    group:      qualified? ? group.handle : nil,
    created_at: created_at.utc.strftime('%FT%TZ')
  }
end

#handleObject



37
38
39
# File 'lib/verdict/assignment.rb', line 37

def handle
  qualified? ? group.handle : nil
end

#permanent?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/verdict/assignment.rb', line 17

def permanent?
  !@temporary
end

#qualified?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/verdict/assignment.rb', line 13

def qualified?
  !group.nil?
end

#returningObject



25
26
27
# File 'lib/verdict/assignment.rb', line 25

def returning
  self.class.new(@experiment, @subject, @group, @created_at)
end

#returning?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/verdict/assignment.rb', line 29

def returning?
  @first.nil?
end

#subject_identifierObject



33
34
35
# File 'lib/verdict/assignment.rb', line 33

def subject_identifier
  experiment.retrieve_subject_identifier(subject)
end

#temporary?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/verdict/assignment.rb', line 21

def temporary?
  @temporary
end

#to_json(options = {}) ⇒ Object



56
57
58
# File 'lib/verdict/assignment.rb', line 56

def to_json(options = {})
  as_json(options).to_json
end

#to_symObject



41
42
43
# File 'lib/verdict/assignment.rb', line 41

def to_sym
  qualified? ? group.to_sym : nil
end