-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.rb
33 lines (29 loc) · 1.07 KB
/
seed.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true
require './classes/library'
require 'active_support/time'
require 'faker'
def seed_db
library = Library.new
authors = []
7.times { authors << Author.new(Faker::Book.unique.author,
Faker::Lorem.paragraph) }
books = []
22.times { books << Book.new(Faker::Book.unique.title,
authors.sample) }
readers = []
6.times { readers << Reader.new(Faker::Name.first_name,
Faker::Internet.unique.email,
Faker::Address.city,
Faker::Address.street_name,
Faker::Address.building_number) }
orders = []
36.times { orders << Order.new(books.sample,
readers.sample,
Faker::Date.between(3.year.ago, 1.day.ago)) }
library.authors = authors
library.books = books
library.readers = readers
library.orders = orders
File.open('ledger.yaml', 'w') { |f| f.write library.to_yaml }
library
end