Class: Garb::ReportParameter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ReportParameter

Returns a new instance of ReportParameter.



6
7
8
9
# File 'lib/garb/report_parameter.rb', line 6

def initialize(name)
  @name = name
  @elements = []
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



4
5
6
# File 'lib/garb/report_parameter.rb', line 4

def elements
  @elements
end

Instance Method Details

#<<(element) ⇒ Object



15
16
17
18
# File 'lib/garb/report_parameter.rb', line 15

def <<(element)
  (@elements += [element].flatten).compact!
  self
end

#nameObject



11
12
13
# File 'lib/garb/report_parameter.rb', line 11

def name
  @name.to_s
end

#to_paramsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/garb/report_parameter.rb', line 20

def to_params
  params = self.elements.map do |elem|
    case elem
    when Hash
      elem.collect do |k,v|
        next unless k.is_a?(Operator)
        "#{k.target}#{URI.encode(k.operator.to_s, /[=<>]/)}#{CGI::escape(v.to_s)}"
      end.join(';')
    else
      elem.to_ga
    end
  end.join(',')
  
  params.empty? ? {} : {self.name => params}
end