class Aruba::Platforms::SimpleTable
Generate simple table
Attributes
hash[R]
Public Class Methods
new(hash)
click to toggle source
Create
@param [Hash] hash
Input
# File lib/aruba/platforms/simple_table.rb, line 17 def initialize(hash) @hash = hash end
Public Instance Methods
to_s()
click to toggle source
Generate table
@return [String]
The table
# File lib/aruba/platforms/simple_table.rb, line 25 def to_s longest_key = hash.keys.map(&:to_s).max_by(&:length) return [] if longest_key.nil? name_size = longest_key.length if RUBY_VERSION < '2' rows = [] hash.each do |k,v| rows << format("# %-#{name_size}s => %s", k, v) end rows.sort else hash.each_with_object([]) do |(k,v), a| a << format("# %-#{name_size}s => %s", k, v) end.sort end end