Class: Ace::Docs::Atoms::TypeInferrer
- Inherits:
-
Object
- Object
- Ace::Docs::Atoms::TypeInferrer
- 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
-
.from_extension(path) ⇒ String?
Infer type from file extension.
-
.resolve(path, pattern_type: nil, frontmatter_type: nil) ⇒ String?
Resolve document type using priority hierarchy: 1.
Class Method Details
.from_extension(path) ⇒ String?
Infer type from file extension
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:
-
Explicit frontmatter doc-type (highest priority)
-
Config pattern type
-
README basename inference
-
File extension inference (lowest priority)
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 |