Sha256: 525e1558807ac5221ffa49b362acd1bea5abb3ee1d9a9b70efddf82b0afb2421

Contents?: true

Size: 811 Bytes

Versions: 66

Compression:

Stored size: 811 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.to_s 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

66 entries across 66 versions & 1 rubygems

Version Path
qwtf_discord_bot-6.3.1 lib/team.rb
qwtf_discord_bot-6.3.0 lib/team.rb
qwtf_discord_bot-6.2.2 lib/team.rb
qwtf_discord_bot-6.2.1 lib/team.rb
qwtf_discord_bot-6.2.0 lib/team.rb
qwtf_discord_bot-6.1.5 lib/team.rb
qwtf_discord_bot-6.1.4 lib/team.rb
qwtf_discord_bot-6.1.3 lib/team.rb
qwtf_discord_bot-6.1.2 lib/team.rb
qwtf_discord_bot-6.1.1 lib/team.rb
qwtf_discord_bot-6.1.0 lib/team.rb
qwtf_discord_bot-6.0.4 lib/team.rb
qwtf_discord_bot-6.0.3 lib/team.rb
qwtf_discord_bot-6.0.2 lib/team.rb
qwtf_discord_bot-6.0.1 lib/team.rb
qwtf_discord_bot-5.5.26 lib/team.rb
qwtf_discord_bot-5.5.25 lib/team.rb
qwtf_discord_bot-5.5.24 lib/team.rb
qwtf_discord_bot-5.5.23 lib/team.rb
qwtf_discord_bot-5.5.22 lib/team.rb