Class: Synthra::Types::TextContent::Slug
- Defined in:
- lib/synthra/types/text_content/text_generation.rb
Overview
Slug type
Generates a URL-friendly slug — lowercase words joined by hyphens, e.g. "building-scalable-apis". Deterministic by seed.
Constant Summary collapse
- WORDS =
Word pool used to assemble slugs (all lowercase, hyphen-safe)
%w[ building scalable apis modern web design fast simple guide getting started with data driven cloud native rust ruby best practices performance tuning real world examples ].freeze
Instance Method Summary collapse
- #generate_edge(rng, context, args) ⇒ Object
- #generate_invalid(rng, context, args) ⇒ Object
-
#generate_random(rng, context, args) ⇒ String
Generate a random slug.
Instance Method Details
#generate_edge(rng, context, args) ⇒ Object
112 113 114 |
# File 'lib/synthra/types/text_content/text_generation.rb', line 112 def generate_edge(rng, context, args) ["", "a", "post"].sample(random: rng.instance_variable_get(:@random)) end |
#generate_invalid(rng, context, args) ⇒ Object
116 117 118 |
# File 'lib/synthra/types/text_content/text_generation.rb', line 116 def generate_invalid(rng, context, args) [nil, 123, [], {}].sample(random: rng.instance_variable_get(:@random)) end |
#generate_random(rng, context, args) ⇒ String
Generate a random slug
105 106 107 108 109 110 |
# File 'lib/synthra/types/text_content/text_generation.rb', line 105 def generate_random(rng, context, args) min = args[:min] || 3 max = args[:max] || 5 count = rng.int(min, max) count.times.map { rng.sample(WORDS) }.join("-") end |