Class: Kameleoon::Targeting::Segment Private

Inherits:
Object
  • Object
show all
Includes:
TreeBuilder
Defined in:
lib/kameleoon/targeting/models.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TreeBuilder

#create_tree

Methods included from ConditionFactory

#get_condition

Constructor Details

#initialize(*args) ⇒ Segment

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Segment.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kameleoon/targeting/models.rb', line 16

def initialize(*args)
  unless args.empty?
    if args.length == 1
      hash = args.first
      if hash.nil?
        raise Kameleoon::Exception::NotFound.new('arguments for segment'), 'arguments for segment'
      end
      if hash['id'].nil?
        raise Kameleoon::Exception::NotFound.new('id'), 'id'
      end
      @id = hash['id'].to_i
      if hash['conditionsData'].nil?
        raise Kameleoon::Exception::NotFound.new(hash['conditionsData']), 'hash[\'conditionsData\']'
      end
      @tree = create_tree(hash['conditionsData'])
    elsif args.length == 2
      @id = args[0]
      @tree = args[1]
    end
  end
end

Instance Attribute Details

#idObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/kameleoon/targeting/models.rb', line 11

def id
  @id
end

#treeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/kameleoon/targeting/models.rb', line 11

def tree
  @tree
end

Instance Method Details

#check_tree(targeting_data) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
41
42
43
44
45
# File 'lib/kameleoon/targeting/models.rb', line 38

def check_tree(targeting_data)
  if @tree.nil?
    is_targeted = true
  else
    is_targeted = @tree.check(targeting_data)
  end
  is_targeted == true
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/kameleoon/targeting/models.rb', line 12

def to_s
  @tree.to_s
end