class Samovar::Output::Rows

Manages hierarchical usage information with support for nesting and formatting.
Represents a collection of rows for usage output.

def << object

@returns [Rows] Self.
@parameter object [Object] The object to add as a row.

Add a row to this collection.
def << object
	@rows << Row.new(object)
	
	return self
end

def columns

@returns [Columns] The columns calculator.

Get the columns for alignment.
def columns
	@columns ||= Columns.new(@rows.select{|row| row.is_a? Array})
end

def each(ignore_nested: false, &block)

@yields {|row, rows| ...} Each row with its parent collection.
@parameter ignore_nested [Boolean] Whether to skip nested rows.

Iterate over each row.
def each(ignore_nested: false, &block)
	return to_enum(:each, ignore_nested: ignore_nested) unless block_given?
	
	@rows.each do |row|
		if row.is_a?(self.class)
			row.each(&block) unless ignore_nested
		else
			yield row, self
		end
	end
end

def empty?

@returns [Boolean] True if there are no rows.

Check if this collection is empty.
def empty?
	@rows.empty?
end

def first

@returns [Object | Nil] The first row.

Get the first row.
def first
	@rows.first
end

def indentation

@returns [String] The indentation string.

Get the indentation string for this level.
def indentation
	@indentation ||= "\t" * @level
end

def initialize(level = 0)

@parameter level [Integer] The indentation level for this collection.

Initialize a new rows collection.
def initialize(level = 0)
	@level = level
	@rows = []
end

def last

@returns [Object | Nil] The last row.

Get the last row.
def last
	@rows.last
end

def nested(*arguments)

@yields {|rows| ...} A block that populates the nested rows.
@parameter arguments [Array] Arguments for the header.

Create a nested section in the output.
def nested(*arguments)
	@rows << Header.new(*arguments)
	
	nested_rows = self.class.new(@level + 1)
	
	yield nested_rows
	
	@rows << nested_rows
end