Class: RChoice::CommandLineChooser

Inherits:
Object
  • Object
show all
Defined in:
lib/rchoice/choosers/command_line_chooser.rb

Instance Method Summary collapse

Instance Method Details

#call(choice) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/rchoice/choosers/command_line_chooser.rb', line 3

def call(choice)
  print_line "Choose #{choice.name}"
  choice.options.each_with_index do |op,i|
    print_line "#{i}. #{choice.option_presenter[op]}"
  end
  get_choice(choice)
end

#get_choice(choice) ⇒ Object



13
14
15
# File 'lib/rchoice/choosers/command_line_chooser.rb', line 13

def get_choice(choice)
  choice.options[get_choice_num]
end

#get_choice_numObject



16
17
18
# File 'lib/rchoice/choosers/command_line_chooser.rb', line 16

def get_choice_num
  STDIN.gets.safe_to_i
end


10
11
12
# File 'lib/rchoice/choosers/command_line_chooser.rb', line 10

def print_line(ln)
  puts ln
end