Class: Goon

Inherits:
Object
  • Object
show all
Defined in:
lib/goon.rb,
lib/goon/version.rb

Defined Under Namespace

Classes: Competency, Task

Constant Summary collapse

VERSION =
'0.0.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Goon

Returns a new instance of Goon.



6
7
8
9
10
11
12
# File 'lib/goon.rb', line 6

def initialize(options = {})
  competencies = options[:competencies] || []
  @competencies = []
  @task = options[:task]
  @facts = options[:facts] || {}
  learn_competencies(competencies)
end

Instance Attribute Details

#competenciesObject (readonly)

Returns the value of attribute competencies.



4
5
6
# File 'lib/goon.rb', line 4

def competencies
  @competencies
end

#factsObject (readonly)

Returns the value of attribute facts.



4
5
6
# File 'lib/goon.rb', line 4

def facts
  @facts
end

#taskObject (readonly)

Returns the value of attribute task.



4
5
6
# File 'lib/goon.rb', line 4

def task
  @task
end

Instance Method Details

#forget(name) ⇒ Object



50
51
52
# File 'lib/goon.rb', line 50

def forget(name)
  @facts.delete(name)
end

#learn_competencies(competencies) ⇒ Object



25
26
27
28
29
# File 'lib/goon.rb', line 25

def learn_competencies(competencies)
  competencies.each do |competency|
    learn_competency(competency)
  end
end

#learn_competency(competency) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/goon.rb', line 14

def learn_competency(competency)
  unless @competencies.include? competency
    instance_eval <<-EOS
    def #{competency.name}(options = {})
      #{competency.body}
    end
    EOS
    @competencies << competency
  end
end

#recall(name) ⇒ Object



46
47
48
# File 'lib/goon.rb', line 46

def recall(name)
  @facts[name]
end

#remember(options = {}) ⇒ Object

end



42
43
44
# File 'lib/goon.rb', line 42

def remember(options = {})
  @facts.merge!(options)
end

#runObject



54
55
56
57
# File 'lib/goon.rb', line 54

def run
  instance_eval @task.body
  @facts
end