Class: Garb::FilterParameters
- Inherits:
-
Object
- Object
- Garb::FilterParameters
- Defined in:
- lib/garb/filter_parameters.rb
Instance Attribute Summary collapse
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Class Method Summary collapse
Instance Method Summary collapse
- #filters(&block) ⇒ Object
-
#initialize ⇒ FilterParameters
constructor
A new instance of FilterParameters.
- #to_params ⇒ Object
Constructor Details
#initialize ⇒ FilterParameters
Returns a new instance of FilterParameters.
18 19 20 |
# File 'lib/garb/filter_parameters.rb', line 18 def initialize self.parameters = [] end |
Instance Attribute Details
#parameters ⇒ Object
Returns the value of attribute parameters.
16 17 18 |
# File 'lib/garb/filter_parameters.rb', line 16 def parameters @parameters end |
Class Method Details
.define_operators(*methods) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/garb/filter_parameters.rb', line 3 def self.define_operators(*methods) methods.each do |method| class_eval <<-CODE def #{method}(field, value) self.parameters << {SymbolOperator.new(field, :#{method}) => value} end CODE end end |
Instance Method Details
#filters(&block) ⇒ Object
22 23 24 |
# File 'lib/garb/filter_parameters.rb', line 22 def filters(&block) instance_eval &block end |
#to_params ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/garb/filter_parameters.rb', line 26 def to_params value = self.parameters.map do |param| param.map do |k,v| next unless k.is_a?(SymbolOperator) "#{URI.encode(k.to_google_analytics, /[=<>]/)}#{CGI::escape(v.to_s)}" end.join(',') # Hash AND end.join(';') # Array OR value.empty? ? {} : {'filters' => value} end |