Class: Lutaml::Model::ComparableModel::Tree
- Inherits:
-
Object
- Object
- Lutaml::Model::ComparableModel::Tree
- Defined in:
- lib/lutaml/model/comparable_model.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#color ⇒ Object
Returns the value of attribute color.
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
-
#initialize(content, color: nil) ⇒ Tree
constructor
A new instance of Tree.
- #to_s(indent = "", is_last = true) ⇒ Object
Constructor Details
#initialize(content, color: nil) ⇒ Tree
112 113 114 115 116 |
# File 'lib/lutaml/model/comparable_model.rb', line 112 def initialize(content, color: nil) @content = content @children = [] @color = color end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
110 111 112 |
# File 'lib/lutaml/model/comparable_model.rb', line 110 def children @children end |
#color ⇒ Object
Returns the value of attribute color.
110 111 112 |
# File 'lib/lutaml/model/comparable_model.rb', line 110 def color @color end |
#content ⇒ Object
Returns the value of attribute content.
110 111 112 |
# File 'lib/lutaml/model/comparable_model.rb', line 110 def content @content end |
Instance Method Details
#add_child(child) ⇒ Object
118 119 120 |
# File 'lib/lutaml/model/comparable_model.rb', line 118 def add_child(child) @children << child end |
#to_s(indent = "", is_last = true) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/lutaml/model/comparable_model.rb', line 122 def to_s(indent = "", is_last = true) prefix = is_last ? "└── " : "├── " result = "#{indent}#{colorize(prefix + @content, @color)}\n" @children.each_with_index do |child, index| is_last_child = index == @children.size - 1 child_indent = indent + (if is_last " " else "#{colorize('│', @color)} " end) result += child.to_s(child_indent, is_last_child) end result end |