Class: Menu
Overview
Collection of menu items
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
Instance Method Summary collapse
- #choose(query = 'Select an item') ⇒ Object
-
#initialize(items) ⇒ Menu
constructor
A new instance of Menu.
Methods included from Prompt
#choose_number, #get_line, #get_text, #url_encode_text, #yn
Constructor Details
#initialize(items) ⇒ Menu
Returns a new instance of Menu.
145 146 147 |
# File 'lib/bunch/url_generator.rb', line 145 def initialize(items) @items = items end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
143 144 145 |
# File 'lib/bunch/url_generator.rb', line 143 def items @items end |
Instance Method Details
#choose(query = 'Select an item') ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/bunch/url_generator.rb', line 149 def choose(query = 'Select an item') throw 'No items initialized' if @items.nil? $stderr.puts warn "┌#{'─' * 74}┐" intpad = Math.log10(@items.length).to_i + 1 @items.each_with_index do |item, idx| idxstr = format("%#{intpad}d", idx + 1) line = "#{idxstr}: #{item.title}" pad = 74 - line.length warn "│#{line}#{' ' * pad}│" end warn "└┤ #{query} ├#{'─' * (70 - query.length)}┘" sel = choose_number('> ', @items.length) sel ? @items[sel.to_i - 1] : nil end |