Class: CLI::Mastermind::ParentPlan
- Inherits:
-
Object
- Object
- CLI::Mastermind::ParentPlan
- Extended by:
- Forwardable
- Includes:
- Plan, Enumerable
- Defined in:
- lib/cli/mastermind/parent_plan.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Used in the interactive plan selector to display child plans.
Instance Method Summary collapse
- #add_children(plans) ⇒ Object
-
#get_child(name) ⇒ Object
(also: #[], #dig)
Get the child plan with the specified
name
. - #has_children? ⇒ Boolean
-
#initialize(name, description = nil, filename = nil, &block) ⇒ ParentPlan
constructor
A new instance of ParentPlan.
Methods included from Plan
Constructor Details
#initialize(name, description = nil, filename = nil, &block) ⇒ ParentPlan
Returns a new instance of ParentPlan.
11 12 13 14 15 |
# File 'lib/cli/mastermind/parent_plan.rb', line 11 def initialize(name, description=nil, filename=nil, &block) super @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Used in the interactive plan selector to display child plans
9 10 11 |
# File 'lib/cli/mastermind/parent_plan.rb', line 9 def children @children end |
Instance Method Details
#add_children(plans) ⇒ Object
27 28 29 30 |
# File 'lib/cli/mastermind/parent_plan.rb', line 27 def add_children(plans) raise InvalidPlanError, 'Cannot add child plans to a plan with an action' unless @block.nil? plans.each(&method(:incorporate_plan)) end |
#get_child(name) ⇒ Object Also known as: [], dig
Get the child plan with the specified name
18 19 20 21 |
# File 'lib/cli/mastermind/parent_plan.rb', line 18 def get_child(name) return @children[name] if @children.has_key? name @children.each_value.find { |child| child.aliases.include? name } end |
#has_children? ⇒ Boolean
32 33 34 |
# File 'lib/cli/mastermind/parent_plan.rb', line 32 def has_children? @children.any? end |