Class: Samovar::Output::Rows
- Inherits:
-
Object
- Object
- Samovar::Output::Rows
- Includes:
- Enumerable
- Defined in:
- lib/samovar/output/rows.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(*arguments) {|nested_rows| ... } ⇒ Object
Constructor Details
#initialize(level = 0) ⇒ Rows
Returns a new instance of Rows.
15 16 17 18 |
# File 'lib/samovar/output/rows.rb', line 15 def initialize(level = 0) @level = level @rows = [] end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
20 21 22 |
# File 'lib/samovar/output/rows.rb', line 20 def level @level end |
Instance Method Details
#<<(object) ⇒ Object
50 51 52 53 54 |
# File 'lib/samovar/output/rows.rb', line 50 def << object @rows << Row.new(object) return self end |
#columns ⇒ Object
56 57 58 |
# File 'lib/samovar/output/rows.rb', line 56 def columns @columns ||= Columns.new(@rows.select{|row| row.is_a? Array}) end |
#each(ignore_nested: false, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/samovar/output/rows.rb', line 38 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
22 23 24 |
# File 'lib/samovar/output/rows.rb', line 22 def empty? @rows.empty? end |
#first ⇒ Object
26 27 28 |
# File 'lib/samovar/output/rows.rb', line 26 def first @rows.first end |
#indentation ⇒ Object
34 35 36 |
# File 'lib/samovar/output/rows.rb', line 34 def indentation @indentation ||= "\t" * @level end |
#last ⇒ Object
30 31 32 |
# File 'lib/samovar/output/rows.rb', line 30 def last @rows.last end |