Method: Doing::WWID#interactive
- Defined in:
- lib/doing/wwid/interactive.rb
#interactive(opt) ⇒ Object
Display an interactive menu of entries
Options hash is shared with #filter_items and #act_on
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/doing/wwid/interactive.rb', line 12 def interactive(opt) opt ||= {} opt[:section] = opt[:section] ? guess_section(opt[:section]) : 'All' search = nil if opt[:search] search = opt[:search] search.sub!(/^'?/, "'") if opt[:exact] opt[:search] = search end # opt[:query] = opt[:search] if opt[:search] && !opt[:query] opt[:query] = "!#{opt[:query]}" if opt[:query] && opt[:not] opt[:multiple] = true opt[:show_if_single] = true = %i[after before case date_filter from fuzzy not search section val].each_with_object({}) { |k, hsh| hsh[k] = opt[k] } items = filter_items(Items.new, opt: ) = %i[search query exact multiple show_if_single menu sort case].each_with_object({}) { |k, hsh| hsh[k] = opt[k] } selection = Prompt.choose_from_items(items, include_section: opt[:section] =~ /^all$/i, **) raise NoResults, 'no items selected' if selection.nil? || selection.empty? act_on(selection, opt) end |