Class: Fir::Suggestion

Inherits:
Object
  • Object
show all
Defined in:
lib/fir/suggestion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, history) ⇒ Suggestion

Returns a new instance of Suggestion.



8
9
10
11
# File 'lib/fir/suggestion.rb', line 8

def initialize(line, history)
  @line = line
  @history = history
end

Instance Attribute Details

#historyObject (readonly)

Returns the value of attribute history.



6
7
8
# File 'lib/fir/suggestion.rb', line 6

def history
  @history
end

#lineObject (readonly)

Returns the value of attribute line.



6
7
8
# File 'lib/fir/suggestion.rb', line 6

def line
  @line
end

Instance Method Details

#filtered_history(str) ⇒ Object



27
28
29
# File 'lib/fir/suggestion.rb', line 27

def filtered_history(str)
  history.grep(/^#{Regexp.escape(str)}/).reverse
end

#generate(i) ⇒ Object



13
14
15
16
17
# File 'lib/fir/suggestion.rb', line 13

def generate(i)
  word = suggestion(line, i)
  return unless word
  word[(line.length)..(word.length)]
end

#suggestion(str, i) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/fir/suggestion.rb', line 19

def suggestion(str, i)
  if str == '' && i.positive?
    history[-i]
  elsif str != ''
    filtered_history(str)[-i]
  end
end