Class: GitRecent::BranchChooser

Inherits:
Object
  • Object
show all
Defined in:
lib/git_recent/branch_chooser.rb

Instance Method Summary collapse

Constructor Details

#initialize(choices, input_stream = $stdin, output_stream = $stdout) ⇒ BranchChooser

Returns a new instance of BranchChooser.


9
10
11
12
13
# File 'lib/git_recent/branch_chooser.rb', line 9

def initialize(choices, input_stream=$stdin, output_stream=$stdout)
  @choices = choices
  @input_stream = input_stream
  @output_stream = output_stream
end

Instance Method Details

#request_choiceObject


15
16
17
18
19
20
21
22
23
24
# File 'lib/git_recent/branch_chooser.rb', line 15

def request_choice
  display_choices

  output_stream.print 'Please select a branch: '
  input = input_stream.gets.strip
  choice_index = input.to_i - 1

  return choices.fetch(choice_index) if valid_choice?(choice_index)
  nil
end