Class: Munger::Render::Text
- Inherits:
-
Object
- Object
- Munger::Render::Text
- Defined in:
- lib/munger/render/text.rb
Instance Attribute Summary collapse
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Instance Method Summary collapse
-
#initialize(report) ⇒ Text
constructor
A new instance of Text.
- #render ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(report) ⇒ Text
Returns a new instance of Text.
7 8 9 |
# File 'lib/munger/render/text.rb', line 7 def initialize(report) @report = report end |
Instance Attribute Details
#report ⇒ Object (readonly)
Returns the value of attribute report.
5 6 7 |
# File 'lib/munger/render/text.rb', line 5 def report @report end |
Instance Method Details
#render ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/munger/render/text.rb', line 11 def render output = '' depth = {} # find depth @report.process_data.each do |row| @report.columns.each do |column| i = row[:data][column].to_s.size depth[column] ||= @report.column_title(column).to_s.size depth[column] = (depth[column] < i) ? i : depth[column] end end # header output += '|' @report.columns.each do |column| output += @report.column_title(column).to_s.ljust(depth[column] + 1) + '| ' end output += "\n" total = depth.values.inject { |sum, i| sum + i } + (depth.size * 3) 0.upto(total) { |i| output += '-' } output += "\n" # body @report.process_data.each do |row| (row[:meta][:group]) ? sep = ':' : sep = '|' output += sep @report.columns.each do |column| output += row[:data][column].to_s.ljust(depth[column] + 1) + sep + ' ' end output += "\n" end output end |