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, Table::CHARS, Table::MIN_FIELD_LENGTH

Instance Attribute Summary

Attributes inherited from Table

#field_lengths, #fields, #max_fields, #width

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Table

#actual_width, #array_to_indices_hash, #call_filter, #chars, #default_field_lengths, #enforce_field_constraints, #filter_values, #format_cell, #format_values, #initialize, #render, #render_border, #render_table_description, #render_table_header, #set_fields, #set_filter_defaults, #set_headers, #set_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 the ones below and :max_fields, :vertical and :max_width which aren’t used.

Options:

:hide_empty

Boolean which hides empty values (nil or ”) from being displayed. Default is false.



7
8
9
# File 'lib/hirb/helpers/vertical_table.rb', line 7

def self.render(rows, options={})
  new(rows, {:escape_special_chars=>false, :resize=>false}.merge(options)).render
end

Instance Method Details



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

def render_footer; []; end

#render_headerObject



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

def render_header; []; end

#render_rowsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hirb/helpers/vertical_table.rb', line 19

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|
      if !@options[:hide_empty] || (@options[:hide_empty] && !row[f].empty?)
        "#{Hirb::String.rjust(@headers[f], longest_header)}: #{row[f]}"
      else
        nil
      end
    }.compact.join("\n")
    i+= 1
    row
  end
end

#setup_field_lengthsObject

:stopdoc:



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

def setup_field_lengths
  @field_lengths = default_field_lengths
end