Class: Hirb::Helpers::VerticalTable
- Defined in:
- lib/hirb/helpers/vertical_table.rb
Constant Summary
Constants inherited from Table
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
- #render_footer ⇒ Object
- #render_header ⇒ Object
- #render_rows ⇒ Object
-
#setup_field_lengths ⇒ Object
:stopdoc:.
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, #set_fields, #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, ={}) new(rows, ).render end |
Instance Method Details
#render_footer ⇒ Object
15 |
# File 'lib/hirb/helpers/vertical_table.rb', line 15 def ; []; end |
#render_header ⇒ Object
14 |
# File 'lib/hirb/helpers/vertical_table.rb', line 14 def render_header; []; end |
#render_rows ⇒ Object
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 = Hirb::String.size @headers.values.sort_by {|e| Hirb::String.size(e) }.last stars = "*" * [(longest_header + (longest_header / 2)), 3].max @rows.map do |row| row = "#{stars} #{i+1}. row #{stars}\n" + @fields.map {|f| "#{Hirb::String.rjust(@headers[f], longest_header)}: #{row[f]}" }.join("\n") i+= 1 row end #:startdoc: end |
#setup_field_lengths ⇒ Object
:stopdoc:
10 11 12 |
# File 'lib/hirb/helpers/vertical_table.rb', line 10 def setup_field_lengths @field_lengths = default_field_lengths end |