Class: Leap::Decision
- Inherits:
-
Object
- Object
- Leap::Decision
- Defined in:
- lib/leap/decision.rb
Overview
Encapsulates a set of strategies to determine a potentially non-obvious attribute of a Leap subject.
Instance Attribute Summary collapse
-
#committees ⇒ Object
readonly
Returns the array of committees defined within the decision block.
-
#goal ⇒ Object
readonly
The goal of the decision, as defined by the first parameter of
Leap::Subject#decide
. -
#signature_method ⇒ Object
readonly
The method name used to retrieve a curated hash of the subject instance’s attributes for use during deliberation.
Instance Method Summary collapse
-
#committee(name, options = {}, &blk) ⇒ Object
Define a committee within the decision.
-
#initialize(goal, options) ⇒ Decision
constructor
Creates a
Leap::Decision
object with a given goal. -
#make(characteristics, options, *considerations) ⇒ Object
Make the decision.
-
#mastered? ⇒ Boolean
Answers whether or not the decision has a “master committee”–a committee with the same name as the decision’s goal.
Constructor Details
#initialize(goal, options) ⇒ Decision
Creates a Leap::Decision
object with a given goal.
Generally you won’t initialize a Leap::Decision
directly; Leap::Subject#decide
does it for you.
20 21 22 23 24 |
# File 'lib/leap/decision.rb', line 20 def initialize(goal, ) @goal = goal @signature_method = [:with] || :_leap_implicit_attributes @committees = [] end |
Instance Attribute Details
#committees ⇒ Object (readonly)
Returns the array of committees defined within the decision block.
11 12 13 |
# File 'lib/leap/decision.rb', line 11 def committees @committees end |
#goal ⇒ Object (readonly)
The goal of the decision, as defined by the first parameter of Leap::Subject#decide
.
5 6 7 |
# File 'lib/leap/decision.rb', line 5 def goal @goal end |
#signature_method ⇒ Object (readonly)
The method name used to retrieve a curated hash of the subject instance’s attributes for use during deliberation. Initially defined by the :with
option on Leap::Subject#decide
.
8 9 10 |
# File 'lib/leap/decision.rb', line 8 def signature_method @signature_method end |
Instance Method Details
#committee(name, options = {}, &blk) ⇒ Object
Define a committee within the decision.
Used within a Leap::Subject#decide
block to define a new committee. See Leap::Committee
for details.
56 57 58 59 60 |
# File 'lib/leap/decision.rb', line 56 def committee(name, = {}, &blk) committee = ::Leap::Committee.new(name, ) @committees << committee committee.instance_eval(&blk) end |
#make(characteristics, options, *considerations) ⇒ Object
Make the decision.
General you won’t call this directly, but rather use the dynamically-created method with this decision’s goal as its name on the subject instance.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/leap/decision.rb', line 35 def make(characteristics, , *considerations) Leap.log.decision "Leaping to conclusion", goal Leap.log.decision "Initial characteristics: #{characteristics.inspect}", goal committees.reject { |c| characteristics.keys.include? c.name }.reverse.inject(Deliberation.new(characteristics)) do |deliberation, committee| Leap.instrument.committee committee.name do if report = committee.report(deliberation.characteristics, considerations, ) Leap.log.committee "Success", committee.name deliberation.reports.unshift report deliberation.characteristics[committee.name] = report.conclusion end Leap.log.decision "Updated characteristics: #{deliberation.characteristics.inspect}", goal end deliberation end end |
#mastered? ⇒ Boolean
Answers whether or not the decision has a “master committee”–a committee with the same name as the decision’s goal.
27 28 29 |
# File 'lib/leap/decision.rb', line 27 def mastered? !!committees.find { |committee| committee.name == goal } end |