Class: Navigator

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

Overview

this class prompts the user for selection and shows “next…” and “prev…” when the user can navigate to the next/prev pages.

Instance Method Summary collapse

Constructor Details

#initialize(paginator) ⇒ Navigator

Returns a new instance of Navigator.



6
7
8
9
# File 'lib/navigator.rb', line 6

def initialize(paginator)
  @paginator = paginator
  @active_index = 1
end

Instance Method Details

#itemsObject



30
31
32
33
34
35
# File 'lib/navigator.rb', line 30

def items
  ii = @paginator.formatted_issues
  ii = ['prev...'] + ii if show_prev?
  ii += ['next...'] if show_next?
  ii
end

#prompt_for_issue_selectionObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/navigator.rb', line 11

def prompt_for_issue_selection
  prompt = TTY::Prompt.new(active_color: :cyan)

  if @paginator.no_issues?
    puts 'No issues found.'
    exit 0
  end

  @selected_index = prompt.select('Select issue:') do |menu|
    menu.default @active_index

    items.each.with_index(1) do |item, i|
      menu.choice item.to_s, i
    end
  end

  handle_selection
end