Class: Riffer::Skills::Frontmatter
- Inherits:
-
Object
- Object
- Riffer::Skills::Frontmatter
- Defined in:
- lib/riffer/skills/frontmatter.rb
Overview
Constant Summary collapse
- NAME_PATTERN =
: Regexp
/\A[a-z0-9]+(-[a-z0-9]+)*\z/- MAX_NAME_LENGTH =
: Integer
64- MAX_DESCRIPTION_LENGTH =
: Integer
1024
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
The skill description (1-1024 chars).
-
#metadata ⇒ Object
readonly
Arbitrary key-value metadata from the spec’s
metadatafield and any unrecognized top-level frontmatter keys. -
#name ⇒ Object
readonly
The skill name (1-64 chars, lowercase alphanumeric and hyphens).
Class Method Summary collapse
-
.parse(raw) ⇒ Object
Parses a raw SKILL.md string into a Frontmatter and body.
-
.parse_frontmatter(raw) ⇒ Object
Parses only the frontmatter from a raw SKILL.md string, ignoring the body.
Instance Method Summary collapse
-
#initialize(name:, description:, metadata: {}) ⇒ Frontmatter
constructor
Creates a new Frontmatter.
Constructor Details
#initialize(name:, description:, metadata: {}) ⇒ Frontmatter
Creates a new Frontmatter.
- name
-
the skill name (must match [a-z0-9](*[a-z0-9])?, 1-64 chars).
- description
-
the skill description (1-1024 chars).
- metadata
-
optional metadata hash.
Raises Riffer::ArgumentError if name or description is invalid.
– : (name: String, description: String, ?metadata: Hash[Symbol, untyped]) -> void
81 82 83 84 85 86 87 |
# File 'lib/riffer/skills/frontmatter.rb', line 81 def initialize(name:, description:, metadata: {}) validate_name!(name) validate_description!(description) @name = name.freeze @description = description.freeze @metadata = .freeze end |
Instance Attribute Details
#description ⇒ Object (readonly)
The skill description (1-1024 chars).
22 23 24 |
# File 'lib/riffer/skills/frontmatter.rb', line 22 def description @description end |
#metadata ⇒ Object (readonly)
Arbitrary key-value metadata from the spec’s metadata field and any unrecognized top-level frontmatter keys.
26 27 28 |
# File 'lib/riffer/skills/frontmatter.rb', line 26 def @metadata end |
#name ⇒ Object (readonly)
The skill name (1-64 chars, lowercase alphanumeric and hyphens).
19 20 21 |
# File 'lib/riffer/skills/frontmatter.rb', line 19 def name @name end |
Class Method Details
.parse(raw) ⇒ Object
Parses a raw SKILL.md string into a Frontmatter and body.
Splits on YAML front matter delimiters (---). Unrecognized top-level keys become metadata. Available to custom backends so they don’t need to reimplement parsing.
Raises Riffer::ArgumentError if frontmatter is invalid.
– : (String) -> [Riffer::Skills::Frontmatter, String]
38 39 40 41 42 |
# File 'lib/riffer/skills/frontmatter.rb', line 38 def self.parse(raw) yaml, body = split_frontmatter(raw) raise Riffer::ArgumentError, "missing YAML frontmatter (expected --- delimiters)" if yaml.empty? [new(name: yaml.delete(:name), description: yaml.delete(:description), metadata: yaml), body] end |
.parse_frontmatter(raw) ⇒ Object
Parses only the frontmatter from a raw SKILL.md string, ignoring the body.
Raises Riffer::ArgumentError if frontmatter is invalid.
– : (String) -> Riffer::Skills::Frontmatter
50 51 52 53 54 |
# File 'lib/riffer/skills/frontmatter.rb', line 50 def self.parse_frontmatter(raw) yaml, _ = split_frontmatter(raw) raise Riffer::ArgumentError, "missing YAML frontmatter (expected --- delimiters)" if yaml.empty? new(name: yaml.delete(:name), description: yaml.delete(:description), metadata: yaml) end |