Class: Cubicle::Aggregation::AggregationView

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/cubicle/aggregation/aggregation_view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregation, query) ⇒ AggregationView

Returns a new instance of AggregationView.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cubicle/aggregation/aggregation_view.rb', line 6

def initialize(aggregation,query)

  time_now = (query.named_expressions.delete(:time_now) || Time.now).to_time

  self[:time_now] = "new Date(#{time_now.to_i*1000})"
  self[:date_today] = "new Date(#{time_now.to_date.to_time.to_i*1000})"
  self[:time_now_iso] = "#{time_now.iso8601}"
  self[:date_today_iso] = "#{time_now.strftime('%Y-%m-%d')}"

  self[:time_now_utc] = "new Date(#{time_now.utc.to_i*1000})"
  self[:date_today_utc] = "new Date(#{time_now.utc.to_date.to_time.to_i*1000})"
  self[:time_now_utc_iso] = "#{time_now.utc.iso8601}"
  self[:date_today_utc_iso] = "#{time_now.utc.strftime('%Y-%m-%d')}"

  list = aggregation.measures + aggregation.dimensions
  list.each do |m|
    self[m.name] = m.expression
  end

  self.merge!(aggregation.named_expressions)
  self.merge!(query.named_expressions)
  
  self.each do |key,value|
    self[key] = expand_template(value)
  end
end

Instance Attribute Details

#aggregationObject

Returns the value of attribute aggregation.



4
5
6
# File 'lib/cubicle/aggregation/aggregation_view.rb', line 4

def aggregation
  @aggregation
end

Instance Method Details

#expand_template(template) ⇒ Object



33
34
35
36
37
38
# File 'lib/cubicle/aggregation/aggregation_view.rb', line 33

def expand_template(template)
  while (template =~ /\{\{\w+\}\}/)
    template = Mustache.render(template,self)
  end
  template
end