Sha256: 51b8dc6d202f11cb03bbde9d80ed403faee0f1b02b559dede50f0289c5dfd586
Contents?: true
Size: 825 Bytes
Versions: 3
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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aruba-1.0.4 | lib/aruba/platforms/simple_table.rb |
aruba-1.0.3 | lib/aruba/platforms/simple_table.rb |
aruba-1.0.2 | lib/aruba/platforms/simple_table.rb |