Sha256: 27da68b9a35bc1f56e3f3b45065302c404a18e796c2b3ebb79acee60b605e22f

Contents?: true

Size: 1022 Bytes

Versions: 8

Compression:

Stored size: 1022 Bytes

Contents

class SymbolOperator
  def initialize(field, operator)
    @field, @operator = field, operator
  end unless method_defined?(:initialize)

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

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

    [:desc, :descending].include?(@operator) ? "#{operator}#{target}" : "#{target}#{operator}"
  end
end

class Symbol
  [:eql, :not_eql, :gt, :gte, :lt, :lte, :desc, :descending,
    :matches, :does_not_match, :contains, :does_not_contain,
    :substring, :not_substring].each do |operator|

    define_method(operator) do
      SymbolOperator.new(self, operator)
    end unless method_defined?(operator)
  end
end

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
readmedia-garb-0.9.1.1 lib/support.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/garb-0.9.1/lib/support.rb
garb-0.9.1 lib/support.rb
garb-0.9.0 lib/support.rb
garb-0.8.5 lib/support.rb
titanous-garb-0.8.7 lib/support.rb
titanous-garb-0.8.5 lib/support.rb
garb-0.8.4 lib/support.rb