Class: SymbolOperator

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

Instance Method Summary collapse

Constructor Details

#initialize(field, operator) ⇒ SymbolOperator

Returns a new instance of SymbolOperator.



2
3
4
# File 'lib/support.rb', line 2

def initialize(field, operator)
  @field, @operator = field, operator
end

Instance Method Details

#to_google_analyticsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/support.rb', line 6

def to_google_analytics
  operators = {
    :eql => '==',
    :not_eql => '!=',
    :gt => '>',
    :gte => '>=',
    :lt => '<',
    :lte => '<=',
    :matches => '==',
    :does_not_match => '!=',
    :contains => '=~',
    :does_not_contain => '!~',
    :substring => '=@',
    :not_substring => '!@',
    :desc => '-'
  }

  target = Garb.to_google_analytics(@field)
  operator = operators[@operator]

  @operator == :desc ? "#{operator}#{target}" : "#{target}#{operator}"
end