class ClientForPoslynx::FakePosTerminal::ConsoleUserInterface::UserButtonNumberSelectionFetcher

Attributes

button_count[R]
selection_listener[R]
ui_context[R]
user_text_line_fetcher[R]

Public Class Methods

new(ui_context, button_count, selection_listener) click to toggle source
# File lib/client_for_poslynx/fake_pos_terminal/console_user_interface/user_button_number_selection_fetcher.rb, line 12
def initialize(ui_context, button_count, selection_listener)
  @ui_context         = ui_context
  @button_count       = button_count
  @selection_listener = selection_listener

  @user_text_line_fetcher = UserTextLineFetcher.new(
    ui_context,
    method(:valid_selection?),
    method(:receive_entry)
  )
end

Public Instance Methods

receive_entry(entry) click to toggle source
# File lib/client_for_poslynx/fake_pos_terminal/console_user_interface/user_button_number_selection_fetcher.rb, line 34
def receive_entry(entry)
  button_num = entry.to_i
  show_selection button_num
  selection_listener.call button_num
end
show_selection(button_num) click to toggle source
# File lib/client_for_poslynx/fake_pos_terminal/console_user_interface/user_button_number_selection_fetcher.rb, line 40
def show_selection(button_num)
  to_start_of_line
  clear_to_end_of_screen
  puts " Selected button #{button_num}"
end
start_process() click to toggle source
# File lib/client_for_poslynx/fake_pos_terminal/console_user_interface/user_button_number_selection_fetcher.rb, line 24
def start_process
  user_text_line_fetcher.call
end
valid_selection?(entry) click to toggle source
# File lib/client_for_poslynx/fake_pos_terminal/console_user_interface/user_button_number_selection_fetcher.rb, line 28
def valid_selection?(entry)
  return false unless entry =~ /\A\d+\Z/
  button_num = entry.to_i
  button_num >= 1 and button_num <= button_count
end