Class: MiniReadline::ArraySource
- Inherits:
-
Object
- Object
- MiniReadline::ArraySource
- Defined in:
- lib/mini_readline/read_line/edit/auto_complete/array_source.rb
Overview
An array as the source for auto-complete.
Instance Method Summary collapse
-
#extract_root_pivot(str) ⇒ Object
Parse the string into the two basic components.
-
#get_array ⇒ Object
Get the array of data from either an array or a block.
-
#initialize(options) ⇒ ArraySource
constructor
Create a new file/folder auto-data source.
-
#next ⇒ Object
Get the next string for auto-complete.
-
#rebuild(str) ⇒ Object
Construct a new data list for auto-complete.
Constructor Details
#initialize(options) ⇒ ArraySource
Create a new file/folder auto-data source. NOP
10 11 12 |
# File 'lib/mini_readline/read_line/edit/auto_complete/array_source.rb', line 10 def initialize() @options = end |
Instance Method Details
#extract_root_pivot(str) ⇒ Object
Parse the string into the two basic components.
24 25 26 |
# File 'lib/mini_readline/read_line/edit/auto_complete/array_source.rb', line 24 def extract_root_pivot(str) @root, @pivot = /\S+$/ =~ str ? [$PREMATCH, $MATCH] : [str, ""] end |
#get_array ⇒ Object
Get the array of data from either an array or a block.
29 30 31 32 33 34 35 |
# File 'lib/mini_readline/read_line/edit/auto_complete/array_source.rb', line 29 def get_array if (src = @options[:array_src]).is_a?(Proc) src.call else src || [] end end |
#next ⇒ Object
Get the next string for auto-complete
38 39 40 |
# File 'lib/mini_readline/read_line/edit/auto_complete/array_source.rb', line 38 def next @root + @cycler.next end |
#rebuild(str) ⇒ Object
Construct a new data list for auto-complete
15 16 17 18 19 20 21 |
# File 'lib/mini_readline/read_line/edit/auto_complete/array_source.rb', line 15 def rebuild(str) extract_root_pivot(str) list = (get_array.select {|entry| entry.start_with?(@pivot)}).sort @cycler = list.empty? ? nil : list.cycle end |