module Tr3llo::Command::Card::Assign
Public Instance Methods
execute(key, board_id)
click to toggle source
# File lib/3llo/command/card/assign.rb, line 7 def execute(key, board_id) card_id = Entities.parse_id(:card, key) assert_card_id!(card_id, key) card = API::Card.find(card_id) interface = Application.fetch_interface!() interface.print_frame do member_ids = select_user(interface, card, board_id) assign_card(card_id, member_ids) interface.puts("Chosen members have been assigned to the card.") end end
Private Instance Methods
assert_card_id!(card_id, key)
click to toggle source
# File lib/3llo/command/card/assign.rb, line 25 def assert_card_id!(card_id, key) raise InvalidArgumentError.new("#{key.inspect} is not a valid list key") unless card_id end
assign_card(card_id, member_ids)
click to toggle source
# File lib/3llo/command/card/assign.rb, line 29 def assign_card(card_id, member_ids) API::Card.assign_members(card_id, member_ids) end
select_user(interface, card, board_id)
click to toggle source
# File lib/3llo/command/card/assign.rb, line 33 def select_user(interface, card, board_id) user_options = API::User.find_all_by_board(board_id) .map { |user| [user.username, user.id] } .to_h() member_ids = card.members.flat_map do |member| index = user_options.find_index { |_username, user_id| user_id == member.id } index ? [index + 1] : [] end interface.input.multi_select( "Choose the users to assign this card to:", user_options, default: member_ids, enum: "." ) end