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.



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

def initialize(level = 0)
	@level = level
	@rows = []
end

Instance Attribute Details

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

#columnsObject



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

Returns:

  • (Boolean)


37
38
39
# File 'lib/samovar/output/rows.rb', line 37

def empty?
	@rows.empty?
end

#firstObject



41
42
43
# File 'lib/samovar/output/rows.rb', line 41

def first
	@rows.first
end

#indentationObject



49
50
51
# File 'lib/samovar/output/rows.rb', line 49

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

#lastObject



45
46
47
# File 'lib/samovar/output/rows.rb', line 45

def last
	@rows.last
end

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

Yields:

  • (nested_rows)


75
76
77
78
79
80
81
82
83
# File 'lib/samovar/output/rows.rb', line 75

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