module Aid class Team attr_reader :members def initialize(members) @members = members.map do |member| Member.new( member["name"], member["github"], member["slack"] ) end end def self.from_yml(path) members = YAML.safe_load(File.read(path))["team"] Team.new(members) end def prompt_for_members puts "Enter their number(s) below. For multiple team members, enter "\ "multiple numbers separated by spaces or commas." puts members.each.with_index do |member, index| puts "#{index + 1}. #{member.name} (@#{member.github_username})" end puts print "> " numbers = $stdin.gets.strip.split(/[^\d]+/) indexes = numbers .map { |num| num.to_i - 1 } .reject { |num| num < 0 } indexes.map { |index| members[index] }.compact end private class Member attr_reader :name, :github_username, :slack_user_id def initialize(name, github_username, slack_user_id) @name = name @github_username = github_username @slack_user_id = slack_user_id end def slack_tag "<@#{slack_user_id}>" end end end end