class ComplexConfig::Tree

@see ComplexConfig::Tree#to_a
@see ComplexConfig::Tree#to_s
@see ComplexConfig::Settings
objects, hashes, arrays, and primitive values.
tree connections and can handle various data types including Settings
settings. It supports both UTF-8 and ASCII character sets for rendering
data, allowing for easy display and understanding of nested configuration
The Tree class is used to create visual tree structures from configuration
data
A tree class that provides hierarchical representation of configuration

def self.convert(name, value)

Returns:
  • (ComplexConfig::Tree) - A tree object representing the hierarchical

Parameters:
  • value (Object) -- The configuration value to convert, which can be a
  • name (Object) -- The name or key to use for the tree node
def self.convert(name, value)
  case value
  when ComplexConfig::Settings
    convert(name, value.to_h)
  when Hash
    obj = new(name.to_s)
    value.each do |name, value|
      obj << convert(name, value)
    end
    obj
  when Array
    obj = new(name.to_s)
    value.each_with_index do |value, i|
      obj << convert(i, value)
    end
    obj
  else
    if name.is_a?(Integer)
      new value.inspect
    else
      new "#{name} = #{value.inspect}"
    end
  end
end

def <<(child)

Returns:
  • (self) - returns self to allow for method chaining after adding the

Parameters:
  • child (ComplexConfig::Tree) -- the child tree node to add to this
def <<(child)
  @children << child
end

def default_utf8

Returns:
  • (TrueClass, FalseClass) - true if the LANG environment variable indicates
def default_utf8
  !!(ENV['LANG'] =~ /utf-8\z/i)
end

def initialize(name, utf8: default_utf8)

Parameters:
  • utf8 (Boolean) -- Whether to use UTF-8 characters for tree rendering,
  • name (Object) -- The name or key to use for the tree node
def initialize(name, utf8: default_utf8)
  @name     = name
  @utf8     = utf8
  @children = []
end

def inner_child_prefix(i)

Returns:
  • (String) - the prefix string for the child node visualization

Parameters:
  • i (Integer) -- the index of the child node in relation to its siblings
def inner_child_prefix(i)
  if @utf8
    i.zero? ? "├─ " : "│  "
  else
    i.zero? ? "+- " : "|  "
  end
end

def last_child_prefix(i)

Returns:
  • (String) - the prefix string for the last child node visualization

Parameters:
  • i (Integer) -- the index of the child node in relation to its siblings
def last_child_prefix(i)
  if @utf8
    i.zero? ? "└─ " : "   "
  else
    i.zero? ? "`- " : "   "
  end
end

def to_ary

Returns:
  • (Array) - an array of formatted strings representing the tree
def to_ary
  to_enum.to_a
end

def to_enum

Returns:
  • (Enumerator) - An enumerator that yields formatted tree node strings
def to_enum
  Enumerator.new do |y|
    y.yield @name
    @children.each_with_index do |child, child_index|
      children_enum = child.to_enum
      if child_index < @children.size - 1
        children_enum.each_with_index do |setting, i|
          y.yield "#{inner_child_prefix(i)}#{setting}"
        end
      else
        children_enum.each_with_index do |setting, i|
          y.yield "#{last_child_prefix(i)}#{setting}"
        end
      end
    end
  end
end

def to_str

Returns:
  • (String) - a newline-separated string containing all tree node representations
def to_str
  to_ary * ?\n
end