File: variant.rb

package info (click to toggle)
ruby-unleash 3.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 252 kB
  • sloc: ruby: 1,098; makefile: 10; sh: 4
file content (23 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Unleash
  class Variant
    attr_accessor :name, :enabled, :payload

    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

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

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