Created
January 23, 2014 17:08
-
-
Save zuchmanski/8582601 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Conference < Generator | |
set_function_name :create_conference | |
set_number CONFERENCE_NUMBER | |
attribute :name, :string do | |
Faker::Company.catch_phrase | |
end | |
attribute :daterange, :daterange do | |
@start_date = (START_DATE..END_DATE).to_a.sample | |
@end_date = @start_date + 3 | |
@start_date..@end_date | |
end | |
attribute :description, :string do | |
"" | |
end | |
attribute :logo, :string do | |
"" | |
end | |
attribute :base_price, :integer do |attrs| | |
rand(100..5000).to_f | |
end | |
attribute :student_discount, :integer do | |
rand(0..0.5).round(2).to_f | |
end | |
attribute :early_birds_discount, :integer do | |
rand(0..0.5).round(2).to_f | |
end | |
attribute :early_birds_ends_at, :datetime do | |
@start_date - rand(30...90) | |
end | |
set_children do |attrs| | |
(@start_date...@end_date).inject("") do |memo, date| | |
memo + Day.new(conference_id: attrs[:parent_id], date: date).output | |
end | |
end | |
end | |
class Day < Generator | |
set_function_name :create_day | |
set_number 1 | |
attribute :conference_id, :integer do |attrs| | |
attrs[:conference_id] | |
end | |
attribute :date, :datetime do |attrs| | |
attrs[:date] | |
end | |
attribute :price, :integer do | |
rand(0..500).to_f | |
end | |
attribute :reservations_limit, :integer do | |
@reservations_limit = rand(100..1000) | |
end | |
set_children do |attrs| | |
(0..rand(0..3)).to_a.inject("") do |memo, _| | |
memo + Workshop.new(day_id: attrs[:parent_id], day_limit: @reservations_limit).output | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment