Class: Hirb::Helpers::VerticalTable

Inherits:
Table
  • Object
show all
Defined in:
lib/hirb/helpers/vertical_table.rb

Constant Summary

Constants inherited from Table

Table::BORDER_LENGTH

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Table

#adjust_long_fields, #array_to_indices_hash, #default_field_lengths, #default_restrict_field_lengths, #filter_values, #format_cell, #initialize, #render, #render_border, #render_table_description, #render_table_header, #restrict_field_lengths, #setup_rows, #validate_values

Constructor Details

This class inherits a constructor from Hirb::Helpers::Table

Class Method Details

.render(rows, options = {}) ⇒ Object

Renders a vertical table using the same options as Hirb::Helpers::Table.render except for :field_lengths, :vertical and :max_width which aren’t used.



5
6
7
# File 'lib/hirb/helpers/vertical_table.rb', line 5

def self.render(rows, options={})
  new(rows, options).render
end

Instance Method Details



15
# File 'lib/hirb/helpers/vertical_table.rb', line 15

def render_footer; []; end

#render_headerObject



14
# File 'lib/hirb/helpers/vertical_table.rb', line 14

def render_header; []; end

#render_rowsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hirb/helpers/vertical_table.rb', line 17

def render_rows
  i = 0
  longest_header = @headers.values.sort_by {|e| e.length}.last.length
  stars = "*" * [(longest_header + (longest_header / 2)), 3].max
  @rows.map do |row|
    row = "#{stars} #{i+1}. row #{stars}\n" +
    @fields.map {|f|
      "#{@headers[f].rjust(longest_header)}: #{row[f]}"
    }.join("\n")
    i+= 1
    row
  end
#:startdoc:
end

#setup_field_lengthsObject

:stopdoc:



10
11
12
# File 'lib/hirb/helpers/vertical_table.rb', line 10

def setup_field_lengths
  @field_lengths = default_field_lengths
end