Class: Lsd::TableFormatter
- Inherits:
-
Object
- Object
- Lsd::TableFormatter
- Defined in:
- lib/lsd/table_formatter.rb
Constant Summary collapse
- MAX_NAME_LENGTH =
30
- AVAILABLE_COLUMNS =
{ "index" => {header: "#", value: ->(entry, idx) { idx.to_s.light_green }}, "name" => {header: "name", value: ->(entry, _) { entry.name.light_cyan }}, "type" => {header: "type", value: ->(entry, _) { entry.type }}, "size" => {header: "size", value: ->(entry, _) { entry.size.light_green }}, "modified" => {header: "modified", value: ->(entry, _) { entry.modified.light_magenta }} }.freeze
- DEFAULT_COLUMNS =
%w[index name type size modified]
- REQUIRED_COLUMNS =
%w[index]
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(entries, columns = DEFAULT_COLUMNS) ⇒ TableFormatter
constructor
A new instance of TableFormatter.
Constructor Details
#initialize(entries, columns = DEFAULT_COLUMNS) ⇒ TableFormatter
19 20 21 22 |
# File 'lib/lsd/table_formatter.rb', line 19 def initialize(entries, columns = DEFAULT_COLUMNS) @entries = entries @columns = process_columns(columns) end |
Class Method Details
.format(entries, columns = DEFAULT_COLUMNS) ⇒ Object
15 16 17 |
# File 'lib/lsd/table_formatter.rb', line 15 def self.format(entries, columns = DEFAULT_COLUMNS) new(entries, columns).format end |
Instance Method Details
#format ⇒ Object
24 25 26 27 28 |
# File 'lib/lsd/table_formatter.rb', line 24 def format table = Terminal::Table.new(headings: headers, rows: formatted_rows, style: {border: :unicode}) table.to_s.gsub(/[┌┐└┘]/, {"┌" => "╭", "┐" => "╮", "└" => "╰", "┘" => "╯"}) end |