Class: ActiveWarehouse::Builder::DateGenerator

Inherits:
AbstractGenerator show all
Defined in:
lib/active_warehouse/builder/random_data_builder.rb

Overview

Basic Date generator

Direct Known Subclasses

TimeGenerator

Instance Method Summary collapse

Instance Method Details

#generate(column, options = {}) ⇒ Object

Generate a random date value

Options:

  • :start_date: The start date as a Date or Time object (default 1 year ago)

  • :end_date: The end date as a Date or Time object (default now)



127
128
129
130
131
132
# File 'lib/active_warehouse/builder/random_data_builder.rb', line 127

def generate(column, options={})
  end_date = (options[:end_date] || Time.now).to_date
  start_date = (options[:start_date] || 1.year.ago).to_date
  number_of_days = end_date - start_date
  start_date + rand(number_of_days)
end