Class: LlmDocsBuilder::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_docs_builder/validator.rb

Overview

Validates llms.txt content against the llms.txt specification

Ensures that llms.txt content follows proper formatting rules including:

  • Required H1 title header

  • Optional description blockquote

  • Proper section ordering (Documentation, Examples, Optional)

  • Valid markdown syntax and link formats

  • File size and line length limits

Examples:

Validate llms.txt content

validator = LlmDocsBuilder::Validator.new(content)
validator.valid? # => true or false
validator.errors # => Array of error messages

Constant Summary collapse

REQUIRED_SECTIONS =

Required sections that must appear in llms.txt

['# '].freeze
OPTIONAL_SECTIONS =

Optional sections that may appear in llms.txt

['> ', '## Documentation', '## Examples', '## Optional'].freeze
MAX_LINE_LENGTH =

Maximum length for a single line in characters

120
MAX_FILE_SIZE =

Maximum file size in bytes

50_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Validator

Initialize a new validator

Parameters:

  • content (String)

    the llms.txt content to validate



41
42
43
44
# File 'lib/llm_docs_builder/validator.rb', line 41

def initialize(content)
  @content = content
  @errors = []
end

Instance Attribute Details

#contentString (readonly)

Returns the llms.txt content being validated.

Returns:

  • (String)

    the llms.txt content being validated



21
22
23
# File 'lib/llm_docs_builder/validator.rb', line 21

def content
  @content
end

#errorsArray<String> (readonly)

Returns array of validation error messages.

Returns:

  • (Array<String>)

    array of validation error messages



24
25
26
# File 'lib/llm_docs_builder/validator.rb', line 24

def errors
  @errors
end

Instance Method Details

#valid?Boolean

Check if content is valid

Runs all validation checks and returns whether the content is valid. Use #errors to access validation error messages.

Returns:

  • (Boolean)

    true if content is valid, false otherwise



52
53
54
55
# File 'lib/llm_docs_builder/validator.rb', line 52

def valid?
  validate!
  errors.empty?
end

#validate!Boolean

Validate content and return result

Runs all validation checks, populates #errors array, and returns whether the content is valid.

Returns:

  • (Boolean)

    true if content is valid, false otherwise



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/llm_docs_builder/validator.rb', line 63

def validate!
  @errors = []

  validate_required_sections
  validate_structure
  validate_markdown_syntax
  validate_links
  validate_file_size

  errors.empty?
end