Class: Samovar::Output::Rows

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/samovar/output.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#levelObject (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

#columnsObject



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

Returns:

  • (Boolean)


86
87
88
# File 'lib/samovar/output.rb', line 86

def empty?
	@rows.empty?
end

#firstObject



90
91
92
# File 'lib/samovar/output.rb', line 90

def first
	@rows.first
end

#indentationObject



98
99
100
# File 'lib/samovar/output.rb', line 98

def indentation
	@indentation ||= "\t" * @level
end

#lastObject



94
95
96
# File 'lib/samovar/output.rb', line 94

def last
	@rows.last
end

#nested(*args) {|nested_rows| ... } ⇒ Object

Yields:

  • (nested_rows)


124
125
126
127
128
129
130
131
132
# File 'lib/samovar/output.rb', line 124

def nested(*args)
	@rows << Header.new(*args)
	
	nested_rows = self.class.new(@level + 1)
	
	yield nested_rows
	
	@rows << nested_rows
end