Class: Leap::Quorum
- Inherits:
-
Object
- Object
- Leap::Quorum
- Defined in:
- lib/leap/quorum.rb
Overview
A basic building block of a Leap decision.
A quorum encapsulates a specific methodology for drawing a conclusion based on a set of input information.
Instance Attribute Summary collapse
-
#compliance ⇒ Object
readonly
Protocols with which this quorum complies.
-
#name ⇒ Object
readonly
The name of the quorum.
-
#process ⇒ Object
readonly
The quorum’s methodology, as a Ruby closure.
-
#requirements ⇒ Object
readonly
Quorum attribute requirements, as defined by the
:needs
option. -
#supplements ⇒ Object
readonly
Useful attributes, as defined by the
:wants
option.
Instance Method Summary collapse
-
#acknowledge(characteristics, considerations) ⇒ Object
Perform the quorum’s methodology using the given characteristics.
-
#characteristics ⇒ Object
All characteristics either needed or wanted by the quorum.
-
#complies_with?(guidelines) ⇒ TrueClass, NilClass
Does the quorum comply with the given set of protocols?.
-
#initialize(name, options, blk) { ... } ⇒ Object
constructor
Defines a quorum within this committee.
-
#satisfied_by?(characteristics) ⇒ TrueClass, NilClass
Do the provided characteristics satisfy the quorum’s requirements?.
Constructor Details
#initialize(name, options, blk) { ... } ⇒ Object
Defines a quorum within this committee.
A quorum encapsulate a specific methodology for drawing the committe’s conclusion.
23 24 25 26 27 28 29 |
# File 'lib/leap/quorum.rb', line 23 def initialize(name, , blk) @name = name @requirements = Array.wrap [:needs] @supplements = Array.wrap [:appreciates] @compliance = Array.wrap [:complies] @process = blk end |
Instance Attribute Details
#compliance ⇒ Object (readonly)
Protocols with which this quorum complies.
20 21 22 |
# File 'lib/leap/quorum.rb', line 20 def compliance @compliance end |
#name ⇒ Object (readonly)
The name of the quorum
8 9 10 |
# File 'lib/leap/quorum.rb', line 8 def name @name end |
#process ⇒ Object (readonly)
The quorum’s methodology, as a Ruby closure.
17 18 19 |
# File 'lib/leap/quorum.rb', line 17 def process @process end |
#requirements ⇒ Object (readonly)
Quorum attribute requirements, as defined by the :needs
option
11 12 13 |
# File 'lib/leap/quorum.rb', line 11 def requirements @requirements end |
#supplements ⇒ Object (readonly)
Useful attributes, as defined by the :wants
option
14 15 16 |
# File 'lib/leap/quorum.rb', line 14 def supplements @supplements end |
Instance Method Details
#acknowledge(characteristics, considerations) ⇒ Object
Perform the quorum’s methodology using the given characteristics.
70 71 72 73 74 75 |
# File 'lib/leap/quorum.rb', line 70 def acknowledge(characteristics, considerations) Leap.instrument.quorum name do considerations.unshift characteristics process.call(*considerations[0...process.arity]) end end |
#characteristics ⇒ Object
All characteristics either needed or wanted by the quorum.
78 79 80 |
# File 'lib/leap/quorum.rb', line 78 def characteristics requirements + supplements end |
#complies_with?(guidelines) ⇒ TrueClass, NilClass
Does the quorum comply with the given set of protocols?
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/leap/quorum.rb', line 41 def complies_with?(guidelines) case guidelines when Hash inversion = guidelines.inject({}) do |memo, pair| protocol, committees = pair Array.wrap(committees).each do |committee| if memo[committee] memo[committee] << protocol else memo[committee] = [protocol] end end memo end inversion.values.any? do |committee_guidelines| (committee_guidelines - compliance).empty? end when Array (guidelines - compliance).empty? when NilClass true else compliance.include? guidelines end end |
#satisfied_by?(characteristics) ⇒ TrueClass, NilClass
Do the provided characteristics satisfy the quorum’s requirements?
34 35 36 |
# File 'lib/leap/quorum.rb', line 34 def satisfied_by?(characteristics) (requirements - characteristics.keys).empty? end |