Module: DemoMode::Clis::MultiWordSearchPatch
- Defined in:
- lib/demo_mode/clis/multi_word_search_patch.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#presented_options(recalculate: false) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity.
Class Method Details
.applied? ⇒ Boolean
14 15 16 |
# File 'lib/demo_mode/clis/multi_word_search_patch.rb', line 14 def self.applied? patched_class < self end |
.apply! ⇒ Object
10 11 12 |
# File 'lib/demo_mode/clis/multi_word_search_patch.rb', line 10 def self.apply! patched_class.prepend(self) unless applied? end |
.patched_class ⇒ Object
18 19 20 |
# File 'lib/demo_mode/clis/multi_word_search_patch.rb', line 18 def self.patched_class CLI::UI::Prompt.const_get(:InteractiveOptions) end |
Instance Method Details
#presented_options(recalculate: false) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/demo_mode/clis/multi_word_search_patch.rb', line 22 def (recalculate: false) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity return @presented_options unless recalculate @presented_options = @options.zip(1..Float::INFINITY) if has_filter? @presented_options.select! do |option, _| @filter.downcase.split.compact.all? do |word| option.downcase.include?(word) end end end # Used for selection purposes @filtered_options = @presented_options.dup @presented_options.unshift([DONE, 0]) if @multiple ensure_visible_is_active if has_filter? while num_lines > max_lines # try to keep the selection centered in the window: if distance_from_selection_to_end > distance_from_start_to_selection # selection is closer to top than bottom, so trim a row from the bottom ensure_last_item_is_continuation_marker @presented_options.delete_at(-2) else # selection is closer to bottom than top, so trim a row from the top ensure_first_item_is_continuation_marker @presented_options.delete_at(1) end end @presented_options end |