Class: TTY2::Reader::Completions Private
- Inherits:
-
Object
- Object
- TTY2::Reader::Completions
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/tty2/reader/completions.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Responsible for storing and navigating completion suggestions
Instance Method Summary collapse
-
#clear ⇒ Object
Clear current completions.
-
#concat(suggestions) ⇒ Object
Add completion suggestions.
-
#each(&block) ⇒ Object
Iterate over all completions.
-
#first? ⇒ Boolean
Check whether the current index is at the first completion or not.
-
#get ⇒ String
Retrieve completion at the current index.
-
#initialize ⇒ Completions
constructor
Create a Completions collection.
-
#last? ⇒ Boolean
Check whether the current index is at the last completion or not.
-
#next ⇒ Object
Move index to the next completion.
-
#previous ⇒ Object
Move index to the previous completion.
Constructor Details
#initialize ⇒ Completions
Create a Completions collection
19 20 21 22 |
# File 'lib/tty2/reader/completions.rb', line 19 def initialize @completions = [] @index = 0 end |
Instance Method Details
#clear ⇒ Object
Clear current completions
27 28 29 30 |
# File 'lib/tty2/reader/completions.rb', line 27 def clear @completions.clear @index = 0 end |
#concat(suggestions) ⇒ Object
Add completion suggestions
56 57 58 |
# File 'lib/tty2/reader/completions.rb', line 56 def concat(suggestions) suggestions.each { |suggestion| @completions << suggestion.dup } end |
#each(&block) ⇒ Object
Iterate over all completions
63 64 65 66 67 68 69 |
# File 'lib/tty2/reader/completions.rb', line 63 def each(&block) if block_given? @completions.each(&block) else @completions.to_enum end end |
#first? ⇒ Boolean
Check whether the current index is at the first completion or not
37 38 39 |
# File 'lib/tty2/reader/completions.rb', line 37 def first? @index.zero? end |
#get ⇒ String
Retrieve completion at the current index
76 77 78 |
# File 'lib/tty2/reader/completions.rb', line 76 def get @completions[@index] end |
#last? ⇒ Boolean
Check whether the current index is at the last completion or not
46 47 48 |
# File 'lib/tty2/reader/completions.rb', line 46 def last? @index == size - 1 end |
#next ⇒ Object
Move index to the next completion
83 84 85 86 87 88 89 90 91 |
# File 'lib/tty2/reader/completions.rb', line 83 def next return if size.zero? if @index == size - 1 @index = 0 else @index += 1 end end |
#previous ⇒ Object
Move index to the previous completion
96 97 98 99 100 101 102 103 104 |
# File 'lib/tty2/reader/completions.rb', line 96 def previous return if size.zero? if @index.zero? @index = size - 1 else @index -= 1 end end |