Class: FieldTest::Participant

Inherits:
Object
  • Object
show all
Defined in:
lib/field_test/participant.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Participant

Returns a new instance of Participant.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/field_test/participant.rb', line 5

def initialize(object)
  if object.is_a?(FieldTest::Participant)
    @type = object.type
    @id = object.id
  elsif object.respond_to?(:model_name)
    @type = object.model_name.name
    @id = object.id.to_s
  else
    @id = object.to_s
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/field_test/participant.rb', line 3

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/field_test/participant.rb', line 3

def type
  @type
end

Class Method Details

.standardize(participant) ⇒ Object



34
35
36
# File 'lib/field_test/participant.rb', line 34

def self.standardize(participant)
  Array(participant).compact.map { |v| FieldTest::Participant.new(v) }
end

Instance Method Details

#participantObject



17
18
19
# File 'lib/field_test/participant.rb', line 17

def participant
  [type, id].compact.join(":")
end

#where_valuesObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/field_test/participant.rb', line 21

def where_values
  if FieldTest.legacy_participants
    {
      participant: participant
    }
  else
    {
      participant_type: type,
      participant_id: id
    }
  end
end