Class: ConfigCat::User

Inherits:
Object
  • Object
show all
Defined in:
lib/configcat/user.rb

Overview

The user object for variation evaluation

Constant Summary collapse

PREDEFINED =
["Identifier", "Email", "Country"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, email: nil, country: nil, custom: nil) ⇒ User

Returns a new instance of User.



8
9
10
11
12
# File 'lib/configcat/user.rb', line 8

def initialize(identifier, email: nil, country: nil, custom: nil)
  @identifier = (!identifier.equal?(nil)) ? identifier : ""
  @data = { "Identifier" => identifier, "Email" => email, "Country" => country }
  @custom = custom
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



6
7
8
# File 'lib/configcat/user.rb', line 6

def identifier
  @identifier
end

Instance Method Details

#get_attribute(attribute) ⇒ Object



18
19
20
21
22
23
# File 'lib/configcat/user.rb', line 18

def get_attribute(attribute)
  attribute = attribute.to_s
  return @data[attribute] if PREDEFINED.include?(attribute)
  return @custom[attribute] if @custom
  return nil
end

#get_identifierObject



14
15
16
# File 'lib/configcat/user.rb', line 14

def get_identifier
  return @identifier
end

#to_sObject



25
26
27
28
29
30
31
32
33
# File 'lib/configcat/user.rb', line 25

def to_s
  dump = {
    'Identifier': @identifier,
    'Email': @data['Email'],
    'Country': @data['Country'],
    'Custom': @custom,
  }
  return dump.to_json
end