Sha256: f2cf0d61ec64199cadc2bd3e54fc4b6d4a613f5a00365aa6367ec84951fa22c1
Contents?: true
Size: 1.25 KB
Versions: 4
Compression:
Stored size: 1.25 KB
Contents
module Bond # Contains search methods used to filter possible completions given what the user has typed for that completion. module Search # Searches completions from the beginning of the string. def default_search(input, list) list.grep(/^#{Regexp.escape(input)}/) end # Searches completions anywhere in the string. def anywhere_search(input, list) list.grep(/#{Regexp.escape(input)}/) end # Searches completions from the beginning and ignores case. def ignore_case_search(input, list) list.grep(/^#{Regexp.escape(input)}/i) end # Searches completions from the beginning but also provides aliasing of underscored words. # For example 'some_dang_long_word' can be specified as 's-d-l-w'. Aliases can be any unique string # at the beginning of an underscored word. For example, to choose the first completion between 'so_long' and 'so_larger', # type 's-lo'. def underscore_search(input, list) if input.include?("-") index = 0 input.split('-').inject(list) {|new_list,e| new_list = new_list.select {|f| f.split(/_+/)[index] =~ /^#{Regexp.escape(e)}/ }; index +=1; new_list } else default_search(input, list) end end end end
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
cldwalker-bond-0.1.3 | lib/bond/search.rb |
cldwalker-bond-0.1.4 | lib/bond/search.rb |
bond-0.1.3 | lib/bond/search.rb |
bond-0.1.4 | lib/bond/search.rb |