Class: Billy::Skill
- Inherits:
-
Object
- Object
- Billy::Skill
- Defined in:
- lib/billygoat/skill.rb
Constant Summary collapse
- ATTRIBUTES =
[:name, :internal_location, :external_location]
Instance Method Summary collapse
- #default_task ⇒ Object
- #documentation(*args) ⇒ Object
- #documentation? ⇒ Boolean
- #execute_task(name, *args) ⇒ Object
- #find_task(name) ⇒ Object
- #has_a_task?(name) ⇒ Boolean
-
#initialize(config = {}) ⇒ Skill
constructor
A new instance of Skill.
- #module ⇒ Object
- #tasks ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
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_task ⇒ Object
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
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
37 38 39 |
# File 'lib/billygoat/skill.rb', line 37 def has_a_task?(name) !!find_task(name) end |
#module ⇒ Object
22 23 24 |
# File 'lib/billygoat/skill.rb', line 22 def module module_from_string(name) end |
#tasks ⇒ Object
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_h ⇒ Object
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_s ⇒ Object
12 13 14 |
# File 'lib/billygoat/skill.rb', line 12 def to_s name end |