Sha256: 11afef3117c6af3d35f605e586fe480dd09499d9e75cc1e440f86fa4f517b3f9
Contents?: true
Size: 825 Bytes
Versions: 7
Compression:
Stored size: 825 Bytes
Contents
# Aruba module Aruba # Platforms module Platforms # Generate simple table class SimpleTable private attr_reader :hash, :opts public # Create # # @param [Hash] hash # Input def initialize(hash, opts) @hash = hash @opts = { sort: true }.merge opts end # Generate table # # @return [String] # The table 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("# %-#{name_size}s => %s", k, v) end if opts[:sort] == true rows.sort.join("\n") else rows.join("\n") end end end end end
Version data entries
7 entries across 7 versions & 2 rubygems