Class: Samovar::Output::Rows
- Inherits:
-
Object
- Object
- Samovar::Output::Rows
- Includes:
- Enumerable
- Defined in:
- lib/samovar/output.rb
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #<<(object) ⇒ Object
- #columns ⇒ Object
- #each(ignore_nested: false, &block) ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
- #indentation ⇒ Object
-
#initialize(level = 0) ⇒ Rows
constructor
A new instance of Rows.
- #last ⇒ Object
- #nested(*args) {|nested_rows| ... } ⇒ Object
Constructor Details
#initialize(level = 0) ⇒ Rows
Returns a new instance of Rows.
79 80 81 82 |
# File 'lib/samovar/output.rb', line 79 def initialize(level = 0) @level = level @rows = [] end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
84 85 86 |
# File 'lib/samovar/output.rb', line 84 def level @level end |
Instance Method Details
#<<(object) ⇒ Object
114 115 116 117 118 |
# File 'lib/samovar/output.rb', line 114 def << object @rows << Row.new(object) return self end |
#columns ⇒ Object
120 121 122 |
# File 'lib/samovar/output.rb', line 120 def columns @columns ||= Columns.new(@rows.select{|row| row.is_a? Array}) end |
#each(ignore_nested: false, &block) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/samovar/output.rb', line 102 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 |
#empty? ⇒ Boolean
86 87 88 |
# File 'lib/samovar/output.rb', line 86 def empty? @rows.empty? end |
#first ⇒ Object
90 91 92 |
# File 'lib/samovar/output.rb', line 90 def first @rows.first end |
#indentation ⇒ Object
98 99 100 |
# File 'lib/samovar/output.rb', line 98 def indentation @indentation ||= "\t" * @level end |
#last ⇒ Object
94 95 96 |
# File 'lib/samovar/output.rb', line 94 def last @rows.last end |