Class: TurnKit::Skill
- Inherits:
-
Object
- Object
- TurnKit::Skill
- Defined in:
- lib/turnkit/skill.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .from_directory(path, pattern: "*.md") ⇒ Object
- .from_file(path, key: nil, name: nil, description: "") ⇒ Object
Instance Method Summary collapse
-
#initialize(key:, name:, content:, description: "") ⇒ Skill
constructor
A new instance of Skill.
Constructor Details
#initialize(key:, name:, content:, description: "") ⇒ Skill
Returns a new instance of Skill.
17 18 19 20 21 22 23 24 25 |
# File 'lib/turnkit/skill.rb', line 17 def initialize(key:, name:, content:, description: "") @key = key.to_s @name = name.to_s @description = description.to_s @content = content.to_s raise ArgumentError, "key is required" if @key.empty? raise ArgumentError, "name is required" if @name.empty? raise ArgumentError, "content is required" if @content.empty? end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'lib/turnkit/skill.rb', line 5 def content @content end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/turnkit/skill.rb', line 5 def description @description end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/turnkit/skill.rb', line 5 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/turnkit/skill.rb', line 5 def name @name end |
Class Method Details
.from_directory(path, pattern: "*.md") ⇒ Object
13 14 15 |
# File 'lib/turnkit/skill.rb', line 13 def self.from_directory(path, pattern: "*.md") Dir.glob(File.join(path, pattern)).sort.map { |file| from_file(file) } end |
.from_file(path, key: nil, name: nil, description: "") ⇒ Object
7 8 9 10 11 |
# File 'lib/turnkit/skill.rb', line 7 def self.from_file(path, key: nil, name: nil, description: "") content = File.read(path) base = File.basename(path, File.extname(path)) new(key: key || base, name: name || base.tr("_-", " ").split.map(&:capitalize).join(" "), description: description, content: content) end |