class Samovar::Output::Rows
Represents a collection of rows for usage output.
Manages hierarchical usage information with support for nesting and formatting.
Attributes
The indentation level.
@attribute [Integer]
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 21 def initialize(level = 0) @level = level @rows = [] end
Initialize a new rows collection.
@parameter level [Integer] The indentation level for this collection.
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 79 def << object @rows << Row.new(object) return self end
Add a row to this collection.
@parameter object [Object] The object to add as a row. @returns [Rows] Self.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 88 def columns @columns ||= Columns.new(@rows.select{|row| row.is_a? Array}) end
Get the columns for alignment.
@returns [Columns] The columns calculator.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 63 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
Iterate over each row.
@parameter ignore_nested [Boolean] Whether to skip nested rows. @yields {|row, rows| …} Each row with its parent collection.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 34 def empty? @rows.empty? end
Check if this collection is empty.
@returns [Boolean] True if there are no rows.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 41 def first @rows.first end
Get the first row.
@returns [Object | Nil] The first row.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 55 def indentation @indentation ||= "\t" * @level end
Get the indentation string for this level.
@returns [String] The indentation string.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 48 def last @rows.last end
Get the last row.
@returns [Object | Nil] The last row.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/rows.rb, line 96 def nested(*arguments) @rows << Header.new(*arguments) nested_rows = self.class.new(@level + 1) yield nested_rows @rows << nested_rows end
Create a nested section in the output.
@parameter arguments [Array] Arguments for the header. @yields {|rows| …} A block that populates the nested rows.