Class: ETL::Builder::DateDimensionBuilder

Inherits:
Object
  • Object
show all
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

@@weekday_indicators =
['Weekend','Weekday','Weekday','Weekday','Weekday','Weekday','Weekend']

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (DateDimensionBuilder) initialize(start_date = Time.now.years_ago(5), end_date = Time.now, fiscal_year_offset_month = 10)

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

- (Object) end_date

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

- (Object) fiscal_year_offset_month

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

- (Object) holiday_indicators

Define any holiday indicators



13
14
15
# File 'lib/etl/builder/date_dimension_builder.rb', line 13

def holiday_indicators
  @holiday_indicators
end

- (Object) start_date

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

- (Object) build(options = {})

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(options={})
  (start_date..end_date).map { |date| record_from_date(date) }
end