Class: Samovar::Output::Rows

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

#columnsObject



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

Returns:

  • (Boolean)


22
23
24
# File 'lib/samovar/output/rows.rb', line 22

def empty?
	@rows.empty?
end

#firstObject



26
27
28
# File 'lib/samovar/output/rows.rb', line 26

def first
	@rows.first
end

#indentationObject



34
35
36
# File 'lib/samovar/output/rows.rb', line 34

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

#lastObject



30
31
32
# File 'lib/samovar/output/rows.rb', line 30

def last
	@rows.last
end

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

Yields:

  • (nested_rows)


60
61
62
63
64
65
66
67
68
# File 'lib/samovar/output/rows.rb', line 60

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