Class: Fir::History
- Inherits:
-
Object
- Object
- Fir::History
- Defined in:
- lib/fir/history.rb
Instance Attribute Summary collapse
-
#active_selection ⇒ Object
readonly
Returns the value of attribute active_selection.
Class Method Summary collapse
Instance Method Summary collapse
- #down ⇒ Object
-
#initialize ⇒ History
constructor
A new instance of History.
- #reset ⇒ Object
- #suggestion(line) ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize ⇒ History
Returns a new instance of History.
10 11 12 |
# File 'lib/fir/history.rb', line 10 def initialize @active_selection = 0 end |
Instance Attribute Details
#active_selection ⇒ Object (readonly)
Returns the value of attribute active_selection.
8 9 10 |
# File 'lib/fir/history.rb', line 8 def active_selection @active_selection end |
Class Method Details
.add_line_to_history_file(line) ⇒ Object
47 48 49 50 |
# File 'lib/fir/history.rb', line 47 def add_line_to_history_file(line) return unless history_file File.open(history_file, 'a') { |f| f.puts(line) } end |
.history ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/fir/history.rb', line 39 def history if history_file && File.exist?(history_file) IO.readlines(history_file).map(&:chomp) else [] end end |
Instance Method Details
#down ⇒ Object
22 23 24 |
# File 'lib/fir/history.rb', line 22 def down @active_selection -= 1 if active_selection.positive? end |
#reset ⇒ Object
14 15 16 |
# File 'lib/fir/history.rb', line 14 def reset @active_selection = 0 end |
#suggestion(line) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/fir/history.rb', line 26 def suggestion(line) Fir::Suggestion.new( line, Fir::History.history ).generate(active_selection) end |
#up ⇒ Object
18 19 20 |
# File 'lib/fir/history.rb', line 18 def up @active_selection += 1 end |