Class: TermiChunk::Report
- Inherits:
-
Object
- Object
- TermiChunk::Report
- Defined in:
- lib/termichunk/report.rb
Constant Summary collapse
- X =
'─'- Y =
'│'- TL =
'┌'- BL =
'└'
Instance Attribute Summary collapse
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#<<(item) ⇒ Object
Add a new entry to the report.
-
#initialize(title:, padding: nil) {|self| ... } ⇒ Report
constructor
Create a new report.
-
#to_s ⇒ String
Retrieve a string-representation of the report.
Constructor Details
#initialize(title:, padding: nil) {|self| ... } ⇒ Report
Create a new report.
16 17 18 19 20 21 |
# File 'lib/termichunk/report.rb', line 16 def initialize(title:, padding: nil) @title = title @padding = padding || 0 @rows = [] yield self if block_given? end |
Instance Attribute Details
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
9 10 11 |
# File 'lib/termichunk/report.rb', line 9 def padding @padding end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
9 10 11 |
# File 'lib/termichunk/report.rb', line 9 def rows @rows end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/termichunk/report.rb', line 9 def title @title end |
Instance Method Details
#<<(item) ⇒ Object
Add a new entry to the report
25 26 27 28 29 30 31 32 |
# File 'lib/termichunk/report.rb', line 25 def <<(item) lines = item.to_s.lines if item.is_a?(self.class) && padding.nonzero? buffer = padding.times.map { "\n" } lines = [*buffer, *lines, *buffer] end lines.each { |l| rows << l } end |
#to_s ⇒ String
Retrieve a string-representation of the report.
36 37 38 39 |
# File 'lib/termichunk/report.rb', line 36 def to_s y = padding.times.map { Y } [(TL), *y, body, *(y if body), (BL)].compact.join("\n") end |