Sha256: 926d9f580c505e44591529aba55c94df4b145269095d5640eadd2dd4bd244238

Contents?: true

Size: 846 Bytes

Versions: 38

Compression:

Stored size: 846 Bytes

Contents

class Team
  attr_accessor :name, :number, :players

  TEAMS = { "blue" => 1, "red" => 2, "yell" => 3, "gren" => 4, "spec" => 5 }.freeze

  def initialize(name)
    @name = build_name(name)
    @number = TEAMS[name] || 5
    @players = []
  end

  def enlist(player)
    @players << player
  end

  def to_embed_field
    Discordrb::Webhooks::EmbedField.new(inline: true, name: field_name, value: player_list)
  end

  private

    def field_name
      name = @name.capitalize
      return "#{name}" unless playing?
      "#{name} | #{score}"
    end

    def playing?
      (1..4).include?(@number)
    end

    def player_list
      players.map(&:to_row).join("\n")
    end

    def score
      return nil if @name == "spec"
      @players.first.score
    end

    def build_name(name)
      return name if TEAMS[name]
      "spec"
    end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
qwtf_discord_bot-4.2.0 lib/team.rb
qwtf_discord_bot-4.1.0 lib/team.rb
qwtf_discord_bot-4.0.3 lib/team.rb
qwtf_discord_bot-4.0.2 lib/team.rb
qwtf_discord_bot-4.0.1 lib/team.rb
qwtf_discord_bot-4.0.0 lib/team.rb
qwtf_discord_bot-3.0.0 lib/team.rb
qwtf_discord_bot-2.2.1 lib/team.rb
qwtf_discord_bot-2.2.0 lib/team.rb
qwtf_discord_bot-2.1.3 lib/team.rb
qwtf_discord_bot-2.1.2 lib/team.rb
qwtf_discord_bot-2.1.1 lib/team.rb
qwtf_discord_bot-2.1.0 lib/team.rb
qwtf_discord_bot-2.0.1 lib/team.rb
qwtf_discord_bot-2.0.0 lib/team.rb
qwtf_discord_bot-1.0.8 lib/team.rb
qwtf_discord_bot-1.0.7 lib/team.rb
qwtf_discord_bot-1.0.6 lib/team.rb