Class: Unleash::Variant

Inherits:
Object
  • Object
show all
Defined in:
lib/unleash/variant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Variant

Returns a new instance of Variant.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
# File 'lib/unleash/variant.rb', line 5

def initialize(params = {})
  raise ArgumentError, "Variant initializer requires a hash." unless params.is_a?(Hash)

  self.name = params.values_at('name', :name).compact.first
  self.enabled = params.values_at('enabled', :enabled).compact.first || false
  self.payload = params.values_at('payload', :payload).compact.first

  raise ArgumentError, "Variant requires a name." if self.name.nil?
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



3
4
5
# File 'lib/unleash/variant.rb', line 3

def enabled
  @enabled
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/unleash/variant.rb', line 3

def name
  @name
end

#payloadObject

Returns the value of attribute payload.



3
4
5
# File 'lib/unleash/variant.rb', line 3

def payload
  @payload
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
# File 'lib/unleash/variant.rb', line 19

def ==(other)
  self.name == other.name && self.enabled == other.enabled && self.payload == other.payload
end

#to_sObject



15
16
17
# File 'lib/unleash/variant.rb', line 15

def to_s
  "<Variant: name=#{self.name},enabled=#{self.enabled},payload=#{self.payload}>"
end