Class: AdminData::Analytics::Dater

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

Overview

a utility class to handle date interpolation for different databases

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, type = 'daily') ⇒ Dater

Returns a new instance of Dater.



10
11
12
13
# File 'lib/admin_data/analytics.rb', line 10

def initialize(adapter, type = 'daily')
  @adapter = adapter
  @type = type
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



8
9
10
# File 'lib/admin_data/analytics.rb', line 8

def adapter
  @adapter
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/admin_data/analytics.rb', line 8

def type
  @type
end

Instance Method Details

#count_functionObject



33
34
35
# File 'lib/admin_data/analytics.rb', line 33

def count_function
  "count(*) as count_data"
end

#count_select_keyObject



29
30
31
# File 'lib/admin_data/analytics.rb', line 29

def count_select_key
  "count_data"
end

#date_select_functionObject



37
38
39
# File 'lib/admin_data/analytics.rb', line 37

def date_select_function
  self.type == 'monthly' ? date_select_function_monthly : date_select_function_daily
end

#date_select_keyObject



15
16
17
# File 'lib/admin_data/analytics.rb', line 15

def date_select_key
  "date_data"
end

#group_by_keyObject



19
20
21
22
23
24
25
26
27
# File 'lib/admin_data/analytics.rb', line 19

def group_by_key
  if adapter =~ /postgresql/i
    self.type == 'monthly' ? "date_part('year', created_at), date_part('month', created_at)" : "date_data"
  elsif adapter =~ /mysql/i
    self.type == 'monthly' ? "YEAR(created_at), MONTH(created_at)" : "date_data"
  else
    self.type == 'monthly' ? "strftime('%Y', created_at), strftime('%m', created_at)" : "date_data"
  end
end