Class: OpenX::TargetingRule
- Inherits:
-
Hash
- Object
- Hash
- OpenX::TargetingRule
- 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
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #compare(value) ⇒ Object
- #complete? ⇒ Boolean
- #equal?(value) ⇒ Boolean (also: #eq?, #is?)
- #exclude?(*values) ⇒ Boolean (also: #does_not_contain?)
- #gt?(value) ⇒ Boolean (also: #>)
- #gte?(value) ⇒ Boolean (also: #>=)
- #include?(*values) ⇒ Boolean (also: #contains?)
-
#initialize(type) ⇒ TargetingRule
constructor
A new instance of TargetingRule.
- #logical(value) ⇒ Object
- #lt?(value) ⇒ Boolean (also: #<)
- #lte?(value) ⇒ Boolean (also: #<=)
- #match?(value) ⇒ Boolean (also: #=~)
- #no_match?(value) ⇒ Boolean
- #not_equal?(value) ⇒ Boolean (also: #ne?, #not?)
- #with(value) ⇒ Object
- #|(other) ⇒ Object
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
#type ⇒ Object (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
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?
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?
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: >
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: >=
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?
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: <
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: <=
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: =~
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
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?
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 |