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.
80 81 82 83 |
# File 'lib/samovar/output.rb', line 80 def initialize(level = 0) @level = level @rows = [] end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
85 86 87 |
# File 'lib/samovar/output.rb', line 85 def level @level end |
Instance Method Details
#<<(object) ⇒ Object
115 116 117 118 119 |
# File 'lib/samovar/output.rb', line 115 def << object @rows << Row.new(object) return self end |
#columns ⇒ Object
121 122 123 |
# File 'lib/samovar/output.rb', line 121 def columns @columns ||= Columns.new(@rows.select{|row| row.is_a? Array}) end |
#each(ignore_nested: false, &block) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/samovar/output.rb', line 103 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
87 88 89 |
# File 'lib/samovar/output.rb', line 87 def empty? @rows.empty? end |
#first ⇒ Object
91 92 93 |
# File 'lib/samovar/output.rb', line 91 def first @rows.first end |
#indentation ⇒ Object
99 100 101 |
# File 'lib/samovar/output.rb', line 99 def indentation @indentation ||= "\t" * @level end |
#last ⇒ Object
95 96 97 |
# File 'lib/samovar/output.rb', line 95 def last @rows.last end |