Class: OpenX::TargetingRule

Inherits:
Hash
  • Object
show all
Defined in:
lib/openx/targeting_rule.rb

Constant Summary collapse

TYPES =
{
  'Client'  => %w(Browser Domain Ip Language Os Useragent),
  'Geo'     => %w(Areacode City Continent Country Dma Latlong Netspeed Organisation Postalcode Region),
  'Site'    => %w(Channel Pageurl Referingpage Source Variable),
  'Time'    => %w(Date Day Hour)
}.freeze
DATA_KEYS =
['comparison', 'data', 'logical'].freeze
ALL_KEYS =
(DATA_KEYS + ['type']).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ TargetingRule

Returns a new instance of TargetingRule.



21
22
23
# File 'lib/openx/targeting_rule.rb', line 21

def initialize(type)
  super().update('type' => verify_type(type), 'logical' => 'and')
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/openx/targeting_rule.rb', line 13

def type
  @type
end

Class Method Details

.instantiate(hash) ⇒ Object



15
16
17
18
19
# File 'lib/openx/targeting_rule.rb', line 15

def self.instantiate(hash)
  rule = new(hash['type'])
  DATA_KEYS.each {|k| rule.update k => hash[k] }
  rule
end

Instance Method Details

#&(other) ⇒ Object



62
63
64
# File 'lib/openx/targeting_rule.rb', line 62

def &(other)
  other.logical('and')
end

#compare(value) ⇒ Object



88
89
90
# File 'lib/openx/targeting_rule.rb', line 88

def compare(value)
  update 'comparison' => value
end

#complete?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/openx/targeting_rule.rb', line 97

def complete?
  values_at(*ALL_KEYS).all? {|v| !v.nil? }
end

#equal?(value) ⇒ Boolean Also known as: eq?, is?

Returns:

  • (Boolean)


25
26
27
# File 'lib/openx/targeting_rule.rb', line 25

def equal?(value)
  update 'comparison' => '==', 'data' => convert(value)
end

#exclude?(*values) ⇒ Boolean Also known as: does_not_contain?

Returns:

  • (Boolean)


79
80
81
# File 'lib/openx/targeting_rule.rb', line 79

def exclude?(*values)
  update 'comparison' => '!~', 'data' => convert(values)
end

#gt?(value) ⇒ Boolean Also known as: >

Returns:

  • (Boolean)


42
43
44
# File 'lib/openx/targeting_rule.rb', line 42

def gt?(value)
  update 'comparison' => '>', 'data' => convert(value)
end

#gte?(value) ⇒ Boolean Also known as: >=

Returns:

  • (Boolean)


52
53
54
# File 'lib/openx/targeting_rule.rb', line 52

def gte?(value)
  update 'comparison' => '>=', 'data' => convert(value)
end

#include?(*values) ⇒ Boolean Also known as: contains?

Returns:

  • (Boolean)


74
75
76
# File 'lib/openx/targeting_rule.rb', line 74

def include?(*values)
  update 'comparison' => '=~', 'data' => convert(values)
end

#logical(value) ⇒ Object



92
93
94
95
# File 'lib/openx/targeting_rule.rb', line 92

def logical(value)
  value = value.to_s
  update 'logical' => (value == 'or' ? value : 'and')
end

#lt?(value) ⇒ Boolean Also known as: <

Returns:

  • (Boolean)


37
38
39
# File 'lib/openx/targeting_rule.rb', line 37

def lt?(value)
  update 'comparison' => '<', 'data' => convert(value)
end

#lte?(value) ⇒ Boolean Also known as: <=

Returns:

  • (Boolean)


47
48
49
# File 'lib/openx/targeting_rule.rb', line 47

def lte?(value)
  update 'comparison' => '<=', 'data' => convert(value)
end

#match?(value) ⇒ Boolean Also known as: =~

Returns:

  • (Boolean)


57
58
59
# File 'lib/openx/targeting_rule.rb', line 57

def match?(value)
  update 'comparison' => '=x', 'data' => convert(value)
end

#no_match?(value) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/openx/targeting_rule.rb', line 70

def no_match?(value)
  update 'comparison' => '!x', 'data' => convert(value)
end

#not_equal?(value) ⇒ Boolean Also known as: ne?, not?

Returns:

  • (Boolean)


31
32
33
# File 'lib/openx/targeting_rule.rb', line 31

def not_equal?(value)
  update 'comparison' => '!=', 'data' => convert(value)
end

#with(value) ⇒ Object



84
85
86
# File 'lib/openx/targeting_rule.rb', line 84

def with(value)
  update 'data' => convert(value)
end

#|(other) ⇒ Object



66
67
68
# File 'lib/openx/targeting_rule.rb', line 66

def |(other)
  other.logical('or')
end