Class: Verdict::Assignment
- Inherits:
-
Object
- Object
- Verdict::Assignment
- Defined in:
- lib/verdict/assignment.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#experiment ⇒ Object
readonly
Returns the value of attribute experiment.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #===(other) ⇒ Object
- #as_json(options = {}) ⇒ Object
- #handle ⇒ Object
-
#initialize(experiment, subject, group, originally_created_at, temporary = false) ⇒ Assignment
constructor
A new instance of Assignment.
- #permanent? ⇒ Boolean
- #qualified? ⇒ Boolean
- #returning ⇒ Object
- #returning? ⇒ Boolean
- #subject_identifier ⇒ Object
- #temporary? ⇒ Boolean
- #to_json(options = {}) ⇒ Object
- #to_sym ⇒ Object
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. @created_at = originally_created_at || Time.now.utc @temporary = temporary end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
2 3 4 |
# File 'lib/verdict/assignment.rb', line 2 def created_at @created_at end |
#experiment ⇒ Object (readonly)
Returns the value of attribute experiment.
2 3 4 |
# File 'lib/verdict/assignment.rb', line 2 def experiment @experiment end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
2 3 4 |
# File 'lib/verdict/assignment.rb', line 2 def group @group end |
#subject ⇒ Object (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( = {}) { experiment: experiment.handle, subject: subject_identifier, qualified: qualified?, returning: returning?, group: qualified? ? group.handle : nil, created_at: created_at.utc.strftime('%FT%TZ') } end |
#handle ⇒ Object
37 38 39 |
# File 'lib/verdict/assignment.rb', line 37 def handle qualified? ? group.handle : nil end |
#permanent? ⇒ Boolean
17 18 19 |
# File 'lib/verdict/assignment.rb', line 17 def permanent? !@temporary end |
#qualified? ⇒ Boolean
13 14 15 |
# File 'lib/verdict/assignment.rb', line 13 def qualified? !group.nil? end |
#returning ⇒ Object
25 26 27 |
# File 'lib/verdict/assignment.rb', line 25 def returning self.class.new(@experiment, @subject, @group, @created_at) end |
#returning? ⇒ Boolean
29 30 31 |
# File 'lib/verdict/assignment.rb', line 29 def returning? @first.nil? end |
#subject_identifier ⇒ Object
33 34 35 |
# File 'lib/verdict/assignment.rb', line 33 def subject_identifier experiment.retrieve_subject_identifier(subject) end |
#temporary? ⇒ 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( = {}) as_json().to_json end |
#to_sym ⇒ Object
41 42 43 |
# File 'lib/verdict/assignment.rb', line 41 def to_sym qualified? ? group.to_sym : nil end |