Sha256: 92b3862aa87549b3fd2c85d6175cdbf63bfbf81824406ef268aca3b3fe032ac6

Contents?: true

Size: 1.5 KB

Versions: 17

Compression:

Stored size: 1.5 KB

Contents

class Verdict::Assignment
  attr_reader :experiment, :subject, :group, :created_at

  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

  def qualified?
    !group.nil?
  end

  def permanent?
    !@temporary
  end

  def temporary?
    @temporary
  end

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

  def returning?
    @first.nil?
  end

  def subject_identifier
    experiment.retrieve_subject_identifier(subject)
  end

  def handle
    qualified? ? group.handle : nil
  end

  def to_sym
    qualified? ? group.to_sym : nil
  end

  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

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

  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
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
verdict-0.16.1 lib/verdict/assignment.rb
verdict-0.16.0 lib/verdict/assignment.rb
verdict-0.15.2 lib/verdict/assignment.rb
verdict-0.15.1 lib/verdict/assignment.rb
verdict-0.15.0 lib/verdict/assignment.rb
verdict-0.14.0 lib/verdict/assignment.rb
verdict-0.13.0 lib/verdict/assignment.rb
verdict-0.12.0 lib/verdict/assignment.rb
verdict-0.11.0 lib/verdict/assignment.rb
verdict-0.10.0 lib/verdict/assignment.rb
verdict-0.9.0 lib/verdict/assignment.rb
verdict-0.8.0 lib/verdict/assignment.rb
verdict-0.7.0 lib/verdict/assignment.rb
verdict-0.6.3 lib/verdict/assignment.rb
verdict-0.6.2 lib/verdict/assignment.rb
verdict-0.6.1 lib/verdict/assignment.rb
verdict-0.6.0 lib/verdict/assignment.rb