Skip to content

Instantly share code, notes, and snippets.

@markets
Last active October 24, 2022 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markets/62665c2d012a96d8ab9805c9484acb8a to your computer and use it in GitHub Desktop.
Save markets/62665c2d012a96d8ab9805c9484acb8a to your computer and use it in GitHub Desktop.
Creates random collections for https://github.com/Subgin/tonic
require "yaml"
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "faker"
end
items = []
categories = 10.times.map { Faker::Company.industry }
tags = 20.times.map { Faker::Company.profession.gsub(" ", "-") }
(ARGV[0] || 20).to_i.times do
items << {
name: Faker::Commerce.product_name,
description: Faker::Lorem.paragraphs(number: 5).join,
summary: Faker::Company.catch_phrase,
category: categories.sample,
tags: tags.sample(rand(1..3)),
status: %w(New Updated Beta).sample,
price: %w(10 15 20 25 30 50 100 300 1000).sample.to_i,
downloads: %w(50 100 200 500 1000 2000).sample.to_i,
images: rand(1..5).times.map { "https://picsum.photos/300" },
premium: [true, false].sample,
website: Faker::Internet.url,
published_at: Faker::Date.between(from: '2018-01-01', to: Date.today).to_s
}.transform_keys(&:to_s)
end
File.write("data/collection.yaml", items.to_yaml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment