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, 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, goal, created_at = Time.now.utc)
  @experiment = experiment
  @subject = subject
  @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

#subjectObject (readonly)

Returns the value of attribute subject.



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

def subject
  @subject
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.lookup(subject)
end

#subject_identifierObject



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

def subject_identifier
  experiment.retrieve_subject_identifier(subject)
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