class Samovar::Output::Rows
Manages hierarchical usage information with support for nesting and formatting.
Represents a collection of rows for usage output.
def << object
@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
Get the columns for alignment.
def columns @columns ||= Columns.new(@rows.select{|row| row.is_a? Array}) end
def each(ignore_nested: false, &block)
@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?
Check if this collection is empty.
def empty? @rows.empty? end
def first
Get the first row.
def first @rows.first end
def indentation
Get the indentation string for this level.
def indentation @indentation ||= "\t" * @level end
def initialize(level = 0)
Initialize a new rows collection.
def initialize(level = 0) @level = level @rows = [] end
def last
Get the last row.
def last @rows.last end
def nested(*arguments)
@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