Class: MakeMenu::BadgeSet
- Inherits:
-
Object
- Object
- MakeMenu::BadgeSet
- Defined in:
- lib/make_menu/badge_set.rb
Overview
A set of BADGES to display above the menu
Instance Method Summary collapse
-
#add(label = '', &block) ⇒ Object
Add a new badge to the set.
-
#display ⇒ Object
Print badges in a wrapping horizontal row.
-
#initialize ⇒ BadgeSet
constructor
A new instance of BadgeSet.
Constructor Details
#initialize ⇒ BadgeSet
Returns a new instance of BadgeSet.
6 7 8 |
# File 'lib/make_menu/badge_set.rb', line 6 def initialize @badges = [] end |
Instance Method Details
#add(label = '', &block) ⇒ Object
Add a new badge to the set
13 14 15 16 17 18 |
# File 'lib/make_menu/badge_set.rb', line 13 def add(label = '', &block) @badges << { label: label, handler: block } end |
#display ⇒ Object
Print badges in a wrapping horizontal row
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/make_menu/badge_set.rb', line 21 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 |