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_identifier ⇒ Object
readonly
Returns the value of attribute subject_identifier.
Instance Method Summary collapse
- #===(other) ⇒ Object
- #as_json(options = {}) ⇒ Object
- #handle ⇒ Object
-
#initialize(experiment, subject_identifier, group, originally_created_at, temporary = false) ⇒ Assignment
constructor
A new instance of Assignment.
- #permanent? ⇒ Boolean
- #qualified? ⇒ Boolean
- #returning ⇒ Object
- #returning? ⇒ Boolean
- #subject ⇒ Object
- #temporary? ⇒ Boolean
- #to_json(options = {}) ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(experiment, subject_identifier, group, originally_created_at, temporary = false) ⇒ Assignment
Returns a new instance of Assignment.
5 6 7 8 9 10 11 12 |
# File 'lib/verdict/assignment.rb', line 5 def initialize(experiment, subject_identifier, group, originally_created_at, temporary = false) @experiment = experiment @subject_identifier = subject_identifier @group = group @returning = !originally_created_at.nil? @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.
3 4 5 |
# File 'lib/verdict/assignment.rb', line 3 def created_at @created_at end |
#experiment ⇒ Object (readonly)
Returns the value of attribute experiment.
3 4 5 |
# File 'lib/verdict/assignment.rb', line 3 def experiment @experiment end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
3 4 5 |
# File 'lib/verdict/assignment.rb', line 3 def group @group end |
#subject_identifier ⇒ Object (readonly)
Returns the value of attribute subject_identifier.
3 4 5 |
# File 'lib/verdict/assignment.rb', line 3 def subject_identifier @subject_identifier end |
Instance Method Details
#===(other) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/verdict/assignment.rb', line 61 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
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/verdict/assignment.rb', line 46 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
38 39 40 |
# File 'lib/verdict/assignment.rb', line 38 def handle qualified? ? group.handle : nil end |
#permanent? ⇒ Boolean
22 23 24 |
# File 'lib/verdict/assignment.rb', line 22 def permanent? !@temporary end |
#qualified? ⇒ Boolean
18 19 20 |
# File 'lib/verdict/assignment.rb', line 18 def qualified? !group.nil? end |
#returning ⇒ Object
30 31 32 |
# File 'lib/verdict/assignment.rb', line 30 def returning self.class.new(@experiment, @subject_identifier, @group, @created_at) end |
#returning? ⇒ Boolean
34 35 36 |
# File 'lib/verdict/assignment.rb', line 34 def returning? @returning end |
#subject ⇒ Object
14 15 16 |
# File 'lib/verdict/assignment.rb', line 14 def subject @subject ||= experiment.fetch_subject(subject_identifier) end |
#temporary? ⇒ Boolean
26 27 28 |
# File 'lib/verdict/assignment.rb', line 26 def temporary? @temporary end |
#to_json(options = {}) ⇒ Object
57 58 59 |
# File 'lib/verdict/assignment.rb', line 57 def to_json( = {}) as_json().to_json end |
#to_sym ⇒ Object
42 43 44 |
# File 'lib/verdict/assignment.rb', line 42 def to_sym qualified? ? group.to_sym : nil end |