Sha256: 838409c9f93ed7ee0d0bf49a0be00536a29a4a59736d83cf0932ec49a42911ae

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
abtion-aid-0.3.2 lib/aid/scripts/shared/team.rb
abtion-aid-0.3.1 lib/aid/scripts/shared/team.rb