Class: FeatBit::User
- Inherits:
-
Object
- Object
- FeatBit::User
- Defined in:
- lib/featbit/user.rb
Instance Attribute Summary collapse
-
#custom ⇒ Object
readonly
Returns the value of attribute custom.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
-
#initialize(key, name: nil, custom: {}) ⇒ User
constructor
A new instance of User.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(key, name: nil, custom: {}) ⇒ User
Returns a new instance of User.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/featbit/user.rb', line 7 def initialize(key, name: nil, custom: {}) @key = deep_freeze(deep_copy(key.to_s)) @name = deep_freeze(deep_copy(name)) unless name.nil? @custom = deep_freeze(deep_copy(custom || {}).transform_keys(&:to_s)) freeze rescue StandardError @key = "" @name = nil @custom = {}.freeze freeze end |
Instance Attribute Details
#custom ⇒ Object (readonly)
Returns the value of attribute custom.
5 6 7 |
# File 'lib/featbit/user.rb', line 5 def custom @custom end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/featbit/user.rb', line 5 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/featbit/user.rb', line 5 def name @name end |
Instance Method Details
#[](attribute) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/featbit/user.rb', line 23 def [](attribute) normalized = attribute.to_s.downcase return key if %w[key keyid targeting_key].include?(normalized) return name if normalized == "name" custom[attribute.to_s] || custom[normalized] rescue StandardError nil end |
#to_h ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/featbit/user.rb', line 33 def to_h { "keyId" => key, "name" => name, "customizedProperties" => custom.map do |property_name, value| { "name" => property_name, "value" => value.to_s } end } end |
#valid? ⇒ Boolean
19 20 21 |
# File 'lib/featbit/user.rb', line 19 def valid? !key.empty? end |