Class: Lightning::Completion

Inherits:
Object
  • Object
show all
Defined in:
lib/lightning/completion.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text_typed, path_key) ⇒ Completion



9
10
11
12
# File 'lib/lightning/completion.rb', line 9

def initialize(text_typed, path_key)
  @text_typed = text_typed
  @path_key = path_key
end

Class Method Details

.complete(text_to_complete, path_key) ⇒ Object



5
6
7
# File 'lib/lightning/completion.rb', line 5

def self.complete(text_to_complete, path_key)
  new(text_to_complete, path_key).matches
end

Instance Method Details

#matchesObject



14
15
16
17
18
# File 'lib/lightning/completion.rb', line 14

def matches
  possible_completions.select do |e|
    e[0, typed.length] == typed
  end
end

#possible_completionsObject



26
27
28
# File 'lib/lightning/completion.rb', line 26

def possible_completions
  Lightning.path_map.completions(@path_key)
end

#typedObject



20
21
22
23
24
# File 'lib/lightning/completion.rb', line 20

def typed
  # @text_typed[/\s(.+?)$/, 1] || ''
  text = @text_typed[/^(\S+)\s+(#{Lightning::TEST_FLAG})?\s*(.+?)$/, 3] || ''
  text.strip
end