Class: Pcrd::Demo::Generator
- Inherits:
-
Object
- Object
- Pcrd::Demo::Generator
- Defined in:
- lib/pcrd/demo/generator.rb
Overview
Generates realistic-looking fake data for the demo schema. Uses no external dependencies — all data is synthesized from built-in arrays.
Constant Summary collapse
- BATCH_SIZE =
500- FIRST_NAMES =
%w[ James Mary Robert Patricia John Jennifer Michael Linda William Barbara David Susan Richard Karen Joseph Lisa Thomas Betty Charles Margaret Christopher Sandra Daniel Ashley Paul Emily Mark Donna George Carol Steven Ruth Kenneth Sharon Edward Michelle Brian Cynthia Ronald Laura Anthony Kimberly Kevin Deborah Jason Rebecca Jeffrey Sharon Gary Helen ].freeze
- LAST_NAMES =
%w[ Smith Johnson Williams Brown Jones Garcia Miller Davis Wilson Anderson Taylor Thomas Hernandez Moore Martin Jackson Thompson White Lopez Lee Gonzalez Harris Clark Lewis Robinson Walker Perez Hall Young Allen Sanchez Wright King Scott Green Baker Adams Nelson Hill Ramirez Campbell Mitchell Roberts Carter Phillips Evans Turner Torres Parker Collins Edwards ].freeze
- EMAIL_DOMAINS =
%w[gmail.com yahoo.com hotmail.com outlook.com icloud.com].freeze
- CITIES_STATES =
[ ["New York", "NY"], ["Los Angeles", "CA"], ["Chicago", "IL"], ["Houston", "TX"], ["Phoenix", "AZ"], ["Philadelphia", "PA"], ["San Antonio", "TX"], ["San Diego", "CA"], ["Dallas", "TX"], ["San Jose", "CA"], ["Austin", "TX"], ["Jacksonville", "FL"], ["Fort Worth", "TX"], ["Columbus", "OH"], ["Charlotte", "NC"], ["San Francisco", "CA"], ["Indianapolis", "IN"], ["Seattle", "WA"], ["Denver", "CO"], ["Nashville", "TN"], ["Oklahoma City", "OK"], ["El Paso", "TX"], ["Boston", "MA"], ["Portland", "OR"], ["Las Vegas", "NV"], ["Memphis", "TN"], ["Louisville", "KY"], ["Baltimore", "MD"], ["Milwaukee", "WI"], ["Albuquerque", "NM"], ["Tucson", "AZ"], ["Fresno", "CA"], ["Sacramento", "CA"], ["Mesa", "AZ"], ["Kansas City", "MO"], ["Atlanta", "GA"], ["Omaha", "NE"], ["Colorado Springs","CO"],["Raleigh", "NC"], ["Long Beach", "CA"], ["Virginia Beach", "VA"], ["Minneapolis", "MN"], ].freeze
- STREET_SUFFIXES =
%w[St Ave Blvd Dr Rd Way Ln Ct Pl Ter Circle].freeze
- STREET_NAMES =
%w[ Oak Maple Pine Cedar Elm Main Park Lake Hill River View Forest Sunset Highland Meadow Ridge Valley Spring Garden Grove Willow Cherry Apple ].freeze
- DESCRIPTIONS =
[ "Charming property in a desirable neighborhood.", "Move-in ready home with modern upgrades throughout.", "Spacious floor plan with abundant natural light.", "Updated kitchen and baths, hardwood floors.", "Corner lot with mature landscaping and privacy.", "Open concept living with high-end finishes.", "Well-maintained property close to top-rated schools.", "Quiet cul-de-sac location, walking distance to parks.", "Investor opportunity or perfect primary residence.", "Stunning views and outdoor entertaining space.", "Classic architecture with contemporary updates.", "Energy-efficient with solar panels and smart features.", ].freeze
Instance Method Summary collapse
-
#generate(listing_count:) ⇒ Object
Generate users, agents, then listings in dependency order.
-
#initialize(pool, seed: 42) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(pool, seed: 42) ⇒ Generator
Returns a new instance of Generator.
66 67 68 69 |
# File 'lib/pcrd/demo/generator.rb', line 66 def initialize(pool, seed: 42) @pool = pool @rng = Random.new(seed) end |
Instance Method Details
#generate(listing_count:) ⇒ Object
Generate users, agents, then listings in dependency order. Returns hash with row counts generated for each table.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pcrd/demo/generator.rb', line 73 def generate(listing_count:) user_count = [[(listing_count / 10).ceil, 50].max, 500].min agent_count = [[(listing_count / 20).ceil, 10].max, 100].min $stdout.puts " Generating #{user_count} users..." user_ids = insert_users(user_count) $stdout.puts " Generating #{agent_count} agents..." agent_ids = insert_agents(agent_count, user_ids: user_ids) $stdout.puts " Generating #{listing_count} listings..." insert_listings(listing_count, agent_ids: agent_ids) { users: user_count, agents: agent_count, listings: listing_count } end |