Class: AmplitudeExperiment::Exposure

Inherits:
Object
  • Object
show all
Defined in:
lib/experiment/local/exposure/exposure.rb

Overview

Exposure is a class that represents a user’s exposure to a set of flags.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, results) ⇒ Exposure

Returns a new instance of Exposure.



6
7
8
9
10
# File 'lib/experiment/local/exposure/exposure.rb', line 6

def initialize(user, results)
  @user = user
  @results = results
  @timestamp = (Time.now.to_f * 1000).to_i
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



4
5
6
# File 'lib/experiment/local/exposure/exposure.rb', line 4

def results
  @results
end

#timestampObject

Returns the value of attribute timestamp.



4
5
6
# File 'lib/experiment/local/exposure/exposure.rb', line 4

def timestamp
  @timestamp
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'lib/experiment/local/exposure/exposure.rb', line 4

def user
  @user
end

Instance Method Details

#canonicalizeObject



12
13
14
15
16
17
18
19
20
# File 'lib/experiment/local/exposure/exposure.rb', line 12

def canonicalize
  sb = "#{@user&.user_id&.strip} #{@user&.device_id&.strip} "
  results.sort.to_h.each do |key, value|
    next unless value.key

    sb += "#{key.strip} #{value.key&.strip} "
  end
  sb
end