class Menu

Collection of menu items

Attributes

items[RW]

Public Class Methods

new(items) click to toggle source
# File lib/bunch/url_generator.rb, line 106
def initialize(items)
  @items = items
end

Public Instance Methods

choose(query = 'Select an item') click to toggle source
# File lib/bunch/url_generator.rb, line 110
def choose(query = 'Select an item')
  throw 'No items initialized' if @items.nil?
  STDERR.puts
  STDERR.puts "┌#{("─" * 74)}┐"
  intpad = Math::log10(@items.length).to_i + 1
  @items.each_with_index do |item, idx|
    idxstr = "%#{intpad}d" % (idx + 1)
    line = "#{idxstr}: #{item.title}"
    pad = 74 - line.length
    STDERR.puts "│#{line}#{" " * pad}│"
  end
  STDERR.puts "└┤ #{query} ├#{"─" * (70 - query.length)}┘"
  sel = choose_number("> ", @items.length)
  sel ? @items[sel.to_i - 1] : nil
end