Module: Bunko::SampleDataGenerator

Defined in:
lib/tasks/support/sample_data_generator.rb

Overview

Simple sample data generator for creating realistic-looking posts No external dependencies - uses built-in Ruby randomization

Constant Summary collapse

NOUNS =

Word pools for generating varied content

%w[system interface component module feature service platform application framework
solution architecture database network security authentication authorization deployment
integration workflow pipeline process functionality capability performance scalability
infrastructure configuration management monitoring analytics documentation implementation
optimization validation testing deployment].freeze
VERBS =
%w[build create develop implement integrate configure optimize enhance improve streamline
automate manage deploy monitor analyze validate test debug refactor scale maintain
upgrade migrate extend customize adapt transform modernize accelerate simplify].freeze
ADJECTIVES =
%w[efficient powerful flexible robust scalable secure reliable fast modern advanced
comprehensive intuitive seamless integrated automated intelligent dynamic responsive
innovative cutting-edge enterprise production-ready cloud-native distributed].freeze
TECH_TERMS =
%w[API REST GraphQL microservice container orchestration Kubernetes Docker CI/CD
authentication JWT OAuth serverless lambda function middleware cache Redis
PostgreSQL MongoDB WebSocket HTTP HTTPS SSL TLS encryption algorithm].freeze
COMPANIES =
%w[TechCorp DataSystems CloudWorks InnovateLabs ScaleUp DevOps Solutions
Enterprise Digital Ventures Analytics Group Platform Technologies
NetworkPro SecureBase CodeCraft BuildTools DeployFirst].freeze
LOREM_WORDS =
%w[lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua enim ad minim veniam quis nostrud
exercitation ullamco laboris nisi aliquip ex ea commodo consequat duis aute
irure in reprehenderit voluptate velit esse cillum fugiat nulla pariatur
excepteur sint occaecat cupidatat non proident sunt culpa qui officia deserunt
mollit anim id est laborum].freeze
[
  {url: "https://github.com/kanejamison/bunko", text: "Bunko on GitHub"},
  {url: "https://rubyonrails.org", text: "Ruby on Rails"},
  {url: "https://www.ruby-lang.org", text: "Ruby Language"},
  {url: "https://rubygems.org", text: "RubyGems"}
].freeze
IMAGE_SIZES =

Random image dimensions from picsum.photos

[
  {width: 800, height: 400, type: :hero},
  {width: 1200, height: 600, type: :hero},
  {width: 700, height: 500, type: :content},
  {width: 600, height: 400, type: :content},
  {width: 500, height: 350, type: :content},
  {width: 400, height: 300, type: :inline}
].freeze
FORMATS =

Supported content formats

[:markdown, :html].freeze

Class Method Summary collapse

Class Method Details

.content_for(post_type_name, target_words:, format: :plain) ⇒ Object

Generate content structure



154
155
156
# File 'lib/tasks/support/sample_data_generator.rb', line 154

def content_for(post_type_name, target_words:, format: :plain)
  default_content(target_words, format)
end

.future_date(months_ahead: 3) ⇒ Object

Generate a random date in the future



134
135
136
137
# File 'lib/tasks/support/sample_data_generator.rb', line 134

def future_date(months_ahead: 3)
  seconds_ahead = rand(0..(months_ahead * 30 * 24 * 60 * 60))
  Time.now + seconds_ahead
end

.paragraph(sentence_count: nil, format: :plain) ⇒ Object

Generate a paragraph with specified sentence count and optional formatting



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/tasks/support/sample_data_generator.rb', line 90

def paragraph(sentence_count: nil, format: :plain)
  # Vary paragraph length: 25% short (1-2 sentences), 75% medium (4-8 sentences)
  sentence_count ||= (rand < 0.25) ? rand(1..2) : rand(4..8)

  text = Array.new(sentence_count) { sentence(format: format) }.join(" ")

  # Wrap in paragraph tags for HTML (20% chance for class)
  if format == :html
    css_class = (rand < 0.2) ? " class=\"content-paragraph\"" : ""
    text = "<p#{css_class}>#{text}</p>"
  end

  text
end

.paragraphs(count: 3, target_words: nil, format: :plain) ⇒ Object

Generate multiple paragraphs with optional formatting



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/tasks/support/sample_data_generator.rb', line 106

def paragraphs(count: 3, target_words: nil, format: :plain)
  paras = if target_words
    # Calculate sentences needed (avg 12 words per sentence)
    sentences_needed = (target_words / 12.0).ceil
    # Group into paragraphs (4-8 sentences each)
    paragraph_count = [(sentences_needed / 6.0).ceil, 1].max

    Array.new(paragraph_count) do
      sentences_in_paragraph = [sentences_needed / paragraph_count, 1].max
      paragraph(sentence_count: sentences_in_paragraph, format: format)
    end
  else
    Array.new(count) { paragraph(format: format) }
  end

  # Randomly add special elements (lists, blockquotes, links)
  paras = inject_special_elements(paras, format) if format != :plain

  paras.join("\n\n")
end

.past_date(years_ago: 2) ⇒ Object

Generate a random date in the past



128
129
130
131
# File 'lib/tasks/support/sample_data_generator.rb', line 128

def past_date(years_ago: 2)
  seconds_ago = rand(0..(years_ago * 365 * 24 * 60 * 60))
  Time.now - seconds_ago
end

.sentence(word_count: nil, capitalize: true, format: :plain) ⇒ Object

Generate a sentence with specified word count and optional formatting



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/tasks/support/sample_data_generator.rb', line 72

def sentence(word_count: nil, capitalize: true, format: :plain)
  # Vary sentence length: 20% short (3-5 words), 80% medium (8-15 words)
  word_count ||= (rand < 0.2) ? rand(3..5) : rand(8..15)

  words = Array.new(word_count) { LOREM_WORDS.sample }
  sentence = words.join(" ")
  sentence = sentence.capitalize if capitalize
  sentence = "#{sentence}."

  # Randomly apply inline formatting (30% chance)
  if format != :plain && rand < 0.3
    sentence = apply_inline_formatting(sentence, format)
  end

  sentence
end

.title_for(post_type_name) ⇒ Object

Generate a title



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/tasks/support/sample_data_generator.rb', line 140

def title_for(post_type_name)
  [
    "#{VERBS.sample.capitalize} Your #{NOUNS.sample.capitalize} with #{ADJECTIVES.sample.capitalize} #{NOUNS.sample.capitalize}",
    "How to #{VERBS.sample.capitalize} #{ADJECTIVES.sample.capitalize} #{NOUNS.sample.capitalize}",
    "The Complete Guide to #{NOUNS.sample.capitalize} #{NOUNS.sample.capitalize}",
    "Understanding #{ADJECTIVES.sample.capitalize} #{NOUNS.sample.capitalize}",
    "#{rand(5..10)} Ways to #{VERBS.sample.capitalize} Your #{NOUNS.sample.capitalize}",
    "#{ADJECTIVES.sample.capitalize} #{NOUNS.sample.capitalize} for #{NOUNS.sample.capitalize}",
    "#{VERBS.sample.capitalize} #{NOUNS.sample.capitalize} Like a Pro",
    "A Deep Dive into #{ADJECTIVES.sample.capitalize} #{NOUNS.sample.capitalize}"
  ].sample
end

.word(type = :general) ⇒ Object

Generate a random word from various pools



60
61
62
63
64
65
66
67
68
69
# File 'lib/tasks/support/sample_data_generator.rb', line 60

def word(type = :general)
  case type
  when :noun then NOUNS.sample
  when :verb then VERBS.sample
  when :adjective then ADJECTIVES.sample
  when :tech then TECH_TERMS.sample
  when :company then COMPANIES.sample
  else LOREM_WORDS.sample
  end
end