Class: Alf::Renderer::Text::Table
- Inherits:
-
Object
- Object
- Alf::Renderer::Text::Table
- Includes:
- Utils
- Defined in:
- lib/alf/renderer/text.rb
Overview
class Row
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #each ⇒ Object
- #each_line(pretty = ) ⇒ Object
-
#initialize(records, attributes, options = {}) ⇒ Table
constructor
A new instance of Table.
- #sep ⇒ Object
- #sizes ⇒ Object
- #to_s ⇒ Object
Methods included from Utils
Constructor Details
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
118 119 120 |
# File 'lib/alf/renderer/text.rb', line 118 def header @header end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
118 119 120 |
# File 'lib/alf/renderer/text.rb', line 118 def @options end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
118 119 120 |
# File 'lib/alf/renderer/text.rb', line 118 def rows @rows end |
Instance Method Details
#each ⇒ Object
148 149 150 151 152 153 |
# File 'lib/alf/renderer/text.rb', line 148 def each return to_enum unless block_given? each_line do |line| yield(line.strip << "\n") end end |
#each_line(pretty = ) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/alf/renderer/text.rb', line 130 def each_line(pretty = [:pretty]) if pretty && trim = [:trim_at] each_line(false) do |line| yield(line[0..trim]) end else yield(sep) yield(header.rendering_lines(sizes).first) yield(sep) rows.each do |row| row.rendering_lines(sizes).each do |line| yield(line) end end yield(sep) end end |
#sep ⇒ Object
126 127 128 |
# File 'lib/alf/renderer/text.rb', line 126 def sep @sep ||= '+-' << sizes.map{|s| '-' * s}.join('-+-') << '-+' end |
#sizes ⇒ Object
120 121 122 123 124 |
# File 'lib/alf/renderer/text.rb', line 120 def sizes @sizes ||= rows.inject(header.min_widths) do |memo,row| memo.zip(row.min_widths).map{|x,y| max(x,y)} end end |
#to_s ⇒ Object
155 156 157 |
# File 'lib/alf/renderer/text.rb', line 155 def to_s each.each_with_object(""){|line,buf| buf << line} end |