Class: Rubydex::Skill

Inherits:
Object
  • Object
show all
Defined in:
lib/rubydex/skill.rb

Overview

A skill file loaded from disk. Skill files are Markdown documents with YAML frontmatter that declare a name and description. The body is the Markdown content after the frontmatter.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, body:) ⇒ Skill

: (name: String, description: String, body: String) -> void



82
83
84
85
86
87
# File 'lib/rubydex/skill.rb', line 82

def initialize(name:, description:, body:)
  @name = name.freeze
  @description = description.freeze
  @body = body.freeze
  freeze
end

Instance Attribute Details

#bodyObject (readonly)

: String



17
18
19
# File 'lib/rubydex/skill.rb', line 17

def body
  @body
end

#descriptionObject (readonly)

: String



14
15
16
# File 'lib/rubydex/skill.rb', line 14

def description
  @description
end

#nameObject (readonly)

: String



11
12
13
# File 'lib/rubydex/skill.rb', line 11

def name
  @name
end

Class Method Details

.from_content(content, path: nil) ⇒ Object

: (String content, ?path: String?) -> Rubydex::Skill



28
29
30
# File 'lib/rubydex/skill.rb', line 28

def from_content(content, path: nil)
  new(**parse(content, path:))
end

.load(path) ⇒ Object

: (String path) -> Rubydex::Skill



21
22
23
24
25
# File 'lib/rubydex/skill.rb', line 21

def load(path)
  from_content(File.read(path), path:)
rescue SystemCallError, IOError => e
  raise SkillError, "Cannot read skill file #{path}: #{e.message}"
end