Class: ETL::Builder::DateDimensionBuilder
- Defined in:
- lib/etl/builder/date_dimension_builder.rb
Overview
A builder which will build a data structure which can be used to populate a date dimension using commonly used date dimension columns.
Constant Summary collapse
- @@weekday_indicators =
['Weekend','Weekday','Weekday','Weekday','Weekday','Weekday','Weekend']
Instance Attribute Summary collapse
-
#end_date ⇒ Object
Specify the end date for the last record.
-
#fiscal_year_offset_month ⇒ Object
Add offset month for fiscal year.
-
#holiday_indicators ⇒ Object
Define any holiday indicators.
-
#start_date ⇒ Object
Specify the start date for the first record.
Instance Method Summary collapse
-
#build(options = {}) ⇒ Object
Returns an array of hashes representing records in the dimension.
-
#initialize(start_date = Time.now.years_ago(5), end_date = Time.now, fiscal_year_offset_month = 10) ⇒ DateDimensionBuilder
constructor
Initialize the builder.
Constructor Details
#initialize(start_date = Time.now.years_ago(5), end_date = Time.now, fiscal_year_offset_month = 10) ⇒ DateDimensionBuilder
Initialize the builder.
-
start_date
: The start date. Defaults to 5 years ago from today. -
end_date
: The end date. Defaults to now.
26 27 28 29 30 31 |
# File 'lib/etl/builder/date_dimension_builder.rb', line 26 def initialize(start_date=Time.now.years_ago(5), end_date=Time.now, fiscal_year_offset_month=10) @start_date = start_date.to_date @end_date = end_date.to_date @fiscal_year_offset_month = fiscal_year_offset_month.to_i @holiday_indicators = [] end |
Instance Attribute Details
#end_date ⇒ Object
Specify the end date for the last record
10 11 12 |
# File 'lib/etl/builder/date_dimension_builder.rb', line 10 def end_date @end_date end |
#fiscal_year_offset_month ⇒ Object
Add offset month for fiscal year
16 17 18 |
# File 'lib/etl/builder/date_dimension_builder.rb', line 16 def fiscal_year_offset_month @fiscal_year_offset_month end |
#holiday_indicators ⇒ Object
Define any holiday indicators
13 14 15 |
# File 'lib/etl/builder/date_dimension_builder.rb', line 13 def holiday_indicators @holiday_indicators end |
#start_date ⇒ Object
Specify the start date for the first record
7 8 9 |
# File 'lib/etl/builder/date_dimension_builder.rb', line 7 def start_date @start_date end |
Instance Method Details
#build(options = {}) ⇒ Object
Returns an array of hashes representing records in the dimension.
34 35 36 |
# File 'lib/etl/builder/date_dimension_builder.rb', line 34 def build(={}) (start_date..end_date).map { |date| record_from_date(date) } end |