Class: Billy::Skill

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

Constant Summary collapse

ATTRIBUTES =
[:name, :internal_location, :external_location]

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Skill

Returns a new instance of Skill.



8
9
10
# File 'lib/billygoat/skill.rb', line 8

def initialize(config = {})
  config.each { |k,v| public_send("#{k}=",v) }
end

Instance Method Details

#default_taskObject



33
34
35
# File 'lib/billygoat/skill.rb', line 33

def default_task
  tasks.first
end

#documentation(*args) ⇒ Object



49
50
51
# File 'lib/billygoat/skill.rb', line 49

def documentation(*args)
  execute_task(:documentation, self, *args)
end

#documentation?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/billygoat/skill.rb', line 45

def documentation?
  !!has_a_task?(:documentation)
end

#execute_task(name, *args) ⇒ Object



53
54
55
56
57
58
# File 'lib/billygoat/skill.rb', line 53

def execute_task(name, *args)
  m = Module.new
  require internal_location
  m.extend(self.module)
  m.send(name, *args)
end

#find_task(name) ⇒ Object



41
42
43
# File 'lib/billygoat/skill.rb', line 41

def find_task(name)
  tasks.detect{ |task| task.name.to_s.downcase == name.to_s.downcase }
end

#has_a_task?(name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/billygoat/skill.rb', line 37

def has_a_task?(name)
  !!find_task(name)
end

#moduleObject



22
23
24
# File 'lib/billygoat/skill.rb', line 22

def module
  module_from_string(name)
end

#tasksObject



26
27
28
29
30
31
# File 'lib/billygoat/skill.rb', line 26

def tasks
  return @tasks if @tasks
  require internal_location if internal_location
  methods = self.module.instance_methods - Object.new.methods
  @tasks = methods.map { |method| Task.new(name: method, skill: self) }
end

#to_hObject



16
17
18
19
20
# File 'lib/billygoat/skill.rb', line 16

def to_h
  ATTRIBUTES.each_with_object({}) do |attribute, hash|
    hash[attribute] = public_send(attribute)
  end
end

#to_sObject



12
13
14
# File 'lib/billygoat/skill.rb', line 12

def to_s
  name
end