Class: Fir::Suggestion
- Inherits:
-
Object
- Object
- Fir::Suggestion
- Defined in:
- lib/fir/suggestion.rb
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #filtered_history(str) ⇒ Object
- #generate(i) ⇒ Object
-
#initialize(line, history) ⇒ Suggestion
constructor
A new instance of Suggestion.
- #suggestion(str, i) ⇒ Object
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
#history ⇒ Object (readonly)
Returns the value of attribute history.
6 7 8 |
# File 'lib/fir/suggestion.rb', line 6 def history @history end |
#line ⇒ Object (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 |