Class: AdminData::Analytics::Dater
- Inherits:
-
Object
- Object
- AdminData::Analytics::Dater
- Defined in:
- lib/admin_data/analytics.rb
Overview
a utility class to handle date interpolation for different databases
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #count_function ⇒ Object
- #count_select_key ⇒ Object
- #date_select_function ⇒ Object
- #date_select_key ⇒ Object
- #group_by_key ⇒ Object
-
#initialize(adapter, type = 'daily') ⇒ Dater
constructor
A new instance of Dater.
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
#adapter ⇒ Object
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/admin_data/analytics.rb', line 8 def adapter @adapter end |
#type ⇒ Object
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_function ⇒ Object
33 34 35 |
# File 'lib/admin_data/analytics.rb', line 33 def count_function "count(*) as count_data" end |
#count_select_key ⇒ Object
29 30 31 |
# File 'lib/admin_data/analytics.rb', line 29 def count_select_key "count_data" end |
#date_select_function ⇒ Object
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_key ⇒ Object
15 16 17 |
# File 'lib/admin_data/analytics.rb', line 15 def date_select_key "date_data" end |
#group_by_key ⇒ Object
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 |