Class: Verdict::Conversion

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(experiment, subject_identifier, goal, created_at = Time.now.utc) ⇒ Conversion

Returns a new instance of Conversion.



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

def initialize(experiment, subject_identifier, goal, created_at = Time.now.utc)
  @experiment = experiment
  @subject_identifier = subject_identifier
  @goal = goal
  @created_at = created_at
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



3
4
5
# File 'lib/verdict/conversion.rb', line 3

def created_at
  @created_at
end

#experimentObject (readonly)

Returns the value of attribute experiment.



3
4
5
# File 'lib/verdict/conversion.rb', line 3

def experiment
  @experiment
end

#goalObject (readonly)

Returns the value of attribute goal.



3
4
5
# File 'lib/verdict/conversion.rb', line 3

def goal
  @goal
end

#subject_identifierObject (readonly)

Returns the value of attribute subject_identifier.



3
4
5
# File 'lib/verdict/conversion.rb', line 3

def subject_identifier
  @subject_identifier
end

Instance Method Details

#as_json(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/verdict/conversion.rb', line 20

def as_json(options = {})
  {
    experiment: experiment.handle,
    subject:    subject_identifier,
    goal:       goal,
    created_at: created_at.utc.strftime('%FT%TZ')
  }
end

#assignmentObject



16
17
18
# File 'lib/verdict/conversion.rb', line 16

def assignment
  experiment.fetch_assignment(subject_identifier)
end

#subjectObject



12
13
14
# File 'lib/verdict/conversion.rb', line 12

def subject
  experiment.fetch_subject(subject_identifier)
end

#to_json(options = {}) ⇒ Object



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

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