Class: TurnKit::Skill

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, name:, content:, description: "") ⇒ Skill

Returns a new instance of Skill.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
# File 'lib/turnkit/skill.rb', line 13

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

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/turnkit/skill.rb', line 5

def content
  @content
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/turnkit/skill.rb', line 5

def description
  @description
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/turnkit/skill.rb', line 5

def key
  @key
end

#nameObject (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_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