Sha256: d86aa9950509520da12e4aae934e4289e18914f1b222dc5caf38399af9451c68
Contents?: true
Size: 790 Bytes
Versions: 16
Compression:
Stored size: 790 Bytes
Contents
# frozen_string_literal: true # Aruba module ProxyRb # Generate simple table class SimpleTable private attr_reader :hash, :opts public # Create # # @param [Hash] hash # Input def initialize(hash, opts = {}) @hash = 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.each_with_object([]) do |(k, v), a| a << format("# %-#{name_size}s => %s", k, v) end if opts[:sort] == true rows.sort.join("\n") else rows.join("\n") end end end end
Version data entries
16 entries across 16 versions & 1 rubygems