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(*args) {|nested_rows| ... } ⇒ Object
Constructor Details
#initialize(level = 0) ⇒ Rows
Returns a new instance of Rows.
30 31 32 33 |
# File 'lib/samovar/output/rows.rb', line 30 def initialize(level = 0) @level = level @rows = [] end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
35 36 37 |
# File 'lib/samovar/output/rows.rb', line 35 def level @level end |
Instance Method Details
#<<(object) ⇒ Object
65 66 67 68 69 |
# File 'lib/samovar/output/rows.rb', line 65 def << object @rows << Row.new(object) return self end |
#columns ⇒ Object
71 72 73 |
# File 'lib/samovar/output/rows.rb', line 71 def columns @columns ||= Columns.new(@rows.select{|row| row.is_a? Array}) end |
#each(ignore_nested: false, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/samovar/output/rows.rb', line 53 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
37 38 39 |
# File 'lib/samovar/output/rows.rb', line 37 def empty? @rows.empty? end |
#first ⇒ Object
41 42 43 |
# File 'lib/samovar/output/rows.rb', line 41 def first @rows.first end |
#indentation ⇒ Object
49 50 51 |
# File 'lib/samovar/output/rows.rb', line 49 def indentation @indentation ||= "\t" * @level end |
#last ⇒ Object
45 46 47 |
# File 'lib/samovar/output/rows.rb', line 45 def last @rows.last end |