Sha256: 957b588e612b017efa2bff3e53f3d1ba24f588109ddc20dfa86b0b63f76cb637

Contents?: true

Size: 634 Bytes

Versions: 1

Compression:

Stored size: 634 Bytes

Contents

module MakeMenu
  class BadgeSet
    def initialize
      @badges = []
    end

    def display
      rows = []
      row = ''
      @badges.each do |badge|
        label = badge[:label]
        value = badge[:handler].call
        if row.decolor.size + label.decolor.size + value.decolor.size >= (0.7 * ::TTY::Screen.cols)
          rows << row
          row = ''
        end
        row += " #{label}#{value} "
      end
      rows << row

      puts rows.join("\n\n").align_block(:center)
      puts
    end

    def add(label = '', &block)
      @badges << {
        label: label,
        handler: block
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
make_menu-2.0.0 lib/make_menu/badge_set.rb