Class: Sod::Presenters::Node

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sod/presenters/node.rb

Overview

Aids in rendering a node for display. :reek:TooManyInstanceVariables

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, indent: 2, gap: 5, action_presenter: Presenters::Action) ⇒ Node

rubocop:todo Metrics/ParameterLists



24
25
26
27
28
29
30
31
# File 'lib/sod/presenters/node.rb', line 24

def initialize(node, indent: 2, gap: 5, action_presenter: Presenters::Action, **)
  super(**)
  @node = node
  @indent = indent
  @gap = gap
  @actions = node.actions.map { |action| action_presenter.new action.record }
  @all = actions + children.to_a
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



21
22
23
# File 'lib/sod/presenters/node.rb', line 21

def actions
  @actions
end

Instance Method Details

#to_sObject

rubocop:enable Metrics/ParameterLists



34
35
36
37
38
# File 'lib/sod/presenters/node.rb', line 34

def to_s
  [banner, body, "", *usage, "", *colored_actions, "", *colored_commands].tap(&:compact!)
                                                                         .join("\n")
                                                                         .strip
end