Class: Pello::Inputs

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

Constant Summary collapse

BACK_OPTION =
'------ BACK ------'.freeze

Class Method Summary collapse

Class Method Details

.choose_board(user, board_url) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/pello/inputs.rb', line 7

def self.choose_board(user, board_url)
  prompt = TTY::Prompt.new
  board_names = user.boards.map(&:name)
  default_board = user.boards.select { |b| b.url == board_url }.first.try(:name)
  board_names << BACK_OPTION
  input = prompt.select('Choose board', board_names, per_page: 15, default: default_board)
  return nil if input == BACK_OPTION

  Pello::Board.new(user.boards.detect { |b| b.name == input })
end

.choose_card(list) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/pello/inputs.rb', line 29

def self.choose_card(list)
  prompt = TTY::Prompt.new
  card_names = list.cards.map(&:name)
  card_names << BACK_OPTION
  input = prompt.select('Choose card', card_names, per_page: 15)
  return nil if input == BACK_OPTION

  Pello::Card.new(list.cards.detect { |c| c.name == input })
end

.choose_list(board, list_name, prompt_text = 'Choose list') ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/pello/inputs.rb', line 18

def self.choose_list(board, list_name, prompt_text = 'Choose list')
  prompt = TTY::Prompt.new
  list_names = board.lists.map(&:name)
  list_names << BACK_OPTION
  default_list = board.lists.select { |l| l.name == list_name }.first.try(:name)
  input = prompt.select(prompt_text, list_names, per_page: 15, default: default_list)
  return nil if input == BACK_OPTION

  Pello::List.new(board.lists.detect { |l| l.name == input })
end