module Learn
Attributes
filepath[RW]
Public Instance Methods
directory(path)
click to toggle source
Learn
a set of new tasks described in a local directory
# File lib/skills/learn.rb, line 29 def directory(path) Dir.glob("#{path}/*.rb").each do |path| file(path) end end
file(path)
click to toggle source
Learn
a new task described in a local file
# File lib/skills/learn.rb, line 6 def file(path) self.filepath = filepath puts "Learning the skill from file #{@filepath}" assert_file_exists create_stash stash_file slate = Module.new slate.module_eval(File.read(internal_location)) skill_name = slate.constants.first.to_s skill = Billy::Skill.new( name: skill_name, internal_location: internal_location ) brain.skill_set.skills << skill brain.update_knowledge brain.save_knowledge end
Private Instance Methods
assert_file_exists()
click to toggle source
# File lib/skills/learn.rb, line 47 def assert_file_exists fail "Naaa, cannot find that file" unless File.exist?(filepath) end
create_stash()
click to toggle source
# File lib/skills/learn.rb, line 51 def create_stash FileUtils.mkdir_p(brain.skills_path) end
filename()
click to toggle source
# File lib/skills/learn.rb, line 39 def filename filepath[/(?<=\/)[^\/]*?$/] end
internal_location()
click to toggle source
# File lib/skills/learn.rb, line 43 def internal_location "#{brain.skills_path}#{filename}" end
stash_file()
click to toggle source
# File lib/skills/learn.rb, line 55 def stash_file FileUtils.cp(filepath, internal_location) end