Class: Rerout::Models::AbVariant
- Inherits:
-
Object
- Object
- Rerout::Models::AbVariant
- Defined in:
- lib/rerout/models.rb
Overview
One A/B-test variant attached to a Smart Link. ‘id` is assigned server-side (read-only); `weight` controls the relative traffic share and defaults to `1`.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#target_url ⇒ Object
readonly
Returns the value of attribute target_url.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(target_url:, weight: 1, id: nil) ⇒ AbVariant
constructor
A new instance of AbVariant.
-
#to_h ⇒ Object
Render for create/update.
Constructor Details
#initialize(target_url:, weight: 1, id: nil) ⇒ AbVariant
Returns a new instance of AbVariant.
151 152 153 154 155 156 |
# File 'lib/rerout/models.rb', line 151 def initialize(target_url:, weight: 1, id: nil) @id = id @target_url = target_url @weight = weight freeze end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
149 150 151 |
# File 'lib/rerout/models.rb', line 149 def id @id end |
#target_url ⇒ Object (readonly)
Returns the value of attribute target_url.
149 150 151 |
# File 'lib/rerout/models.rb', line 149 def target_url @target_url end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
149 150 151 |
# File 'lib/rerout/models.rb', line 149 def weight @weight end |
Class Method Details
.from_hash(hash) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/rerout/models.rb', line 158 def self.from_hash(hash) new( id: hash['id'], target_url: hash['target_url'], weight: hash.fetch('weight', 1) ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
171 172 173 174 |
# File 'lib/rerout/models.rb', line 171 def ==(other) other.is_a?(AbVariant) && other.id == id && other.target_url == target_url && other.weight == weight end |
#hash ⇒ Object
177 178 179 |
# File 'lib/rerout/models.rb', line 177 def hash [self.class, id, target_url, weight].hash end |
#to_h ⇒ Object
Render for create/update. The server-assigned ‘id` is never sent.
167 168 169 |
# File 'lib/rerout/models.rb', line 167 def to_h { 'target_url' => target_url, 'weight' => weight } end |