Class: Synthra::Types::TextContent::Slug

Inherits:
Base
  • Object
show all
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.

Examples:

Generate a slug

slug_type = Slug.new
slug_type.generate_random(rng, context, {})
# => "building-scalable-apis"

Constant Summary collapse

WORDS =

Word pool used to assemble slugs (all lowercase, hyphen-safe)

Returns:

  • (Array<String>)

    candidate slug words

%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

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

Parameters:

Options Hash (args):

  • :min (Integer)

    minimum word count (default: 3)

  • :max (Integer)

    maximum word count (default: 5)

Returns:

  • (String)

    generated 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