Class: Ace::Docs::Atoms::TypeInferrer

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/docs/atoms/type_inferrer.rb

Overview

Infers document type from file extension and patterns with configurable priority hierarchy

Constant Summary collapse

EXTENSION_MAP =

Map of file extensions to document types

{
  ".wf.md" => "workflow",
  ".g.md" => "guide",
  ".template.md" => "template",
  ".api.md" => "api"
}.freeze

Class Method Summary collapse

Class Method Details

.from_extension(path) ⇒ String?

Infer type from file extension

Parameters:

  • path (String)

    File path

Returns:

  • (String, nil)

    Document type or nil



20
21
22
23
24
25
# File 'lib/ace/docs/atoms/type_inferrer.rb', line 20

def self.from_extension(path)
  EXTENSION_MAP.each do |ext, type|
    return type if path.end_with?(ext)
  end
  nil
end

.resolve(path, pattern_type: nil, frontmatter_type: nil) ⇒ String?

Resolve document type using priority hierarchy:

  1. Explicit frontmatter doc-type (highest priority)

  2. Config pattern type

  3. README basename inference

  4. File extension inference (lowest priority)

Parameters:

  • path (String)

    File path

  • pattern_type (String, nil) (defaults to: nil)

    Type from config pattern matching

  • frontmatter_type (String, nil) (defaults to: nil)

    Explicit doc-type from frontmatter

Returns:

  • (String, nil)

    Resolved document type



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ace/docs/atoms/type_inferrer.rb', line 37

def self.resolve(path, pattern_type: nil, frontmatter_type: nil)
  # Priority 1: Explicit frontmatter (overrides everything)
  return frontmatter_type if frontmatter_type && !frontmatter_type.empty?

  # Priority 2: Config pattern type
  return pattern_type if pattern_type && !pattern_type.empty?

  # Priority 3: Basename inference
  if File.basename(path).casecmp("README.md").zero?
    return "root_readme" if root_readme?(path)

    return "readme"
  end

  # Priority 4: Extension-based inference
  extension_type = from_extension(path)
  return extension_type if extension_type

  nil
end