Class: Tracker::Cli::View::Select
- Inherits:
-
Object
- Object
- Tracker::Cli::View::Select
- Defined in:
- lib/tracker/cli/view/select.rb
Instance Attribute Summary collapse
-
#selection ⇒ Object
readonly
Returns the value of attribute selection.
Instance Method Summary collapse
-
#initialize(prompt, options) ⇒ Select
constructor
A new instance of Select.
Constructor Details
#initialize(prompt, options) ⇒ Select
Returns a new instance of Select.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tracker/cli/view/select.rb', line 7 def initialize(prompt, ) .each_with_index do |option, index| $stderr.print "(#{index + 1}) #{block_given? ? yield(option) : option}\n" end loop do $stderr.print "\n#{prompt} " user_input = $stdin.gets.chomp index = user_input.to_i selection = [index - 1] if index.to_s != user_input $stderr.print "Please make a selection.\n" elsif selection.nil? $stderr.print "Please select one of the options above.\n" else @selection = selection break end end $stderr.print "\n" end |
Instance Attribute Details
#selection ⇒ Object (readonly)
Returns the value of attribute selection.
5 6 7 |
# File 'lib/tracker/cli/view/select.rb', line 5 def selection @selection end |