Class: Saulabs::Reportable::Grouping
- Inherits:
-
Object
- Object
- Saulabs::Reportable::Grouping
- Defined in:
- lib/saulabs/reportable/grouping.rb
Overview
The grouping specifies which records are grouped into one ReportingPeriod.
Instance Method Summary collapse
-
#date_parts_from_db_string(db_string) ⇒ Array<Fixnum>
Gets an array of date parts from a DB string.
-
#identifier ⇒ Symbol
Gets the identifier of the grouping.
-
#initialize(identifier) ⇒ Grouping
constructor
Initializes a new grouping.
-
#to_sql(date_column) ⇒ Object
Converts the grouping into a DB specific string that can be used to group records.
Constructor Details
#initialize(identifier) ⇒ Grouping
Initializes a new grouping.
14 15 16 17 |
# File 'lib/saulabs/reportable/grouping.rb', line 14 def initialize(identifier) raise ArgumentError.new("Invalid grouping #{identifier}") unless [:hour, :day, :week, :month].include?(identifier) @identifier = identifier end |
Instance Method Details
#date_parts_from_db_string(db_string) ⇒ Array<Fixnum>
Gets an array of date parts from a DB string.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/saulabs/reportable/grouping.rb', line 36 def date_parts_from_db_string(db_string) case ActiveRecord::Base.connection.adapter_name when /mysql/i from_mysql_db_string(db_string) when /sqlite/i from_sqlite_db_string(db_string) when /postgres/i from_postgresql_db_string(db_string) end end |
#identifier ⇒ Symbol
Gets the identifier of the grouping.
24 25 26 |
# File 'lib/saulabs/reportable/grouping.rb', line 24 def identifier @identifier end |
#to_sql(date_column) ⇒ Object
Converts the grouping into a DB specific string that can be used to group records.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/saulabs/reportable/grouping.rb', line 52 def to_sql(date_column) case ActiveRecord::Base.connection.adapter_name when /mysql/i mysql_format(date_column) when /sqlite/i sqlite_format(date_column) when /postgres/i postgresql_format(date_column) end end |