Class: Rerout::Models::RoutingRule

Inherits:
Object
  • Object
show all
Defined in:
lib/rerout/models.rb

Overview

A Smart Link routing rule — send matching visitors to ‘target_url`. `condition_type` is `“country”` or `“device”`; `condition_op` is `“is”`, `“is_not”`, or `“in”`; `condition_value` is the value to compare against (e.g. `“US”` or `“US,CA,GB”` for `“in”`).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition_type:, condition_op:, condition_value:, target_url:) ⇒ RoutingRule

Returns a new instance of RoutingRule.



109
110
111
112
113
114
115
# File 'lib/rerout/models.rb', line 109

def initialize(condition_type:, condition_op:, condition_value:, target_url:)
  @condition_type = condition_type
  @condition_op = condition_op
  @condition_value = condition_value
  @target_url = target_url
  freeze
end

Instance Attribute Details

#condition_opObject (readonly)

Returns the value of attribute condition_op.



107
108
109
# File 'lib/rerout/models.rb', line 107

def condition_op
  @condition_op
end

#condition_typeObject (readonly)

Returns the value of attribute condition_type.



107
108
109
# File 'lib/rerout/models.rb', line 107

def condition_type
  @condition_type
end

#condition_valueObject (readonly)

Returns the value of attribute condition_value.



107
108
109
# File 'lib/rerout/models.rb', line 107

def condition_value
  @condition_value
end

#target_urlObject (readonly)

Returns the value of attribute target_url.



107
108
109
# File 'lib/rerout/models.rb', line 107

def target_url
  @target_url
end

Class Method Details

.from_hash(hash) ⇒ Object



117
118
119
120
121
122
123
124
# File 'lib/rerout/models.rb', line 117

def self.from_hash(hash)
  new(
    condition_type: hash['condition_type'],
    condition_op: hash['condition_op'],
    condition_value: hash['condition_value'],
    target_url: hash['target_url']
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



135
136
137
# File 'lib/rerout/models.rb', line 135

def ==(other)
  other.is_a?(RoutingRule) && other.to_h == to_h
end

#hashObject



140
141
142
# File 'lib/rerout/models.rb', line 140

def hash
  to_h.hash
end

#to_hObject



126
127
128
129
130
131
132
133
# File 'lib/rerout/models.rb', line 126

def to_h
  {
    'condition_type' => condition_type,
    'condition_op' => condition_op,
    'condition_value' => condition_value,
    'target_url' => target_url
  }
end