Class: Aruba::Platforms::SimpleTable
- Inherits:
-
Object
- Object
- Aruba::Platforms::SimpleTable
- Defined in:
- lib/aruba/platforms/simple_table.rb
Overview
Generate simple table
Instance Method Summary collapse
-
#initialize(hash, sort: true) ⇒ SimpleTable
constructor
Create.
-
#to_s ⇒ String
Generate table.
Constructor Details
#initialize(hash, sort: true) ⇒ SimpleTable
Create
13 14 15 16 |
# File 'lib/aruba/platforms/simple_table.rb', line 13 def initialize(hash, sort: true) @hash = hash @sort = sort end |
Instance Method Details
#to_s ⇒ String
Generate table
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aruba/platforms/simple_table.rb', line 22 def to_s longest_key = hash.keys.map(&:to_s).max_by(&:length) return '' if longest_key.nil? name_size = longest_key.length rows = hash.map do |k, v| format('# %-*s => %s', name_size, k, v) end if sort rows.sort.join("\n") else rows.join("\n") end end |