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
Returns a new instance of Tree.
138 139 140 141 142 |
# File 'lib/lutaml/model/comparable_model.rb', line 138 def initialize(content, color: nil) @content = content @children = [] @color = color end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
136 137 138 |
# File 'lib/lutaml/model/comparable_model.rb', line 136 def children @children end |
#color ⇒ Object
Returns the value of attribute color.
136 137 138 |
# File 'lib/lutaml/model/comparable_model.rb', line 136 def color @color end |
#content ⇒ Object
Returns the value of attribute content.
136 137 138 |
# File 'lib/lutaml/model/comparable_model.rb', line 136 def content @content end |
Instance Method Details
#add_child(child) ⇒ Object
144 145 146 |
# File 'lib/lutaml/model/comparable_model.rb', line 144 def add_child(child) @children << child end |
#to_s(indent = "", is_last = true) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/lutaml/model/comparable_model.rb', line 148 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 |