<commit_before>class Game < ApplicationRecord
  validates :name, presence: true, uniqueness: true

  belongs_to :creator, class_name: User
  has_many :rounds
  has_many :teams
  has_many :turns, through: :rounds
  has_and_belongs_to_many :participants,
                          join_table: "games_participants",
                          class_name: User,
                          association_foreign_key: 'participant_id'

  after_create :initialize_rounds


  def to_param
    name
  end

  def is_over?
    self.rounds.all? { |round| round.is_over? }
  end

  def current_round
    return nil if self.is_over?
    self.rounds.each do |round|
      return round unless round.is_over?
    end
  end

  def get_cluegiver
    next_turn_team.players.shuffle.min_by do |player|
      self.count_turns(player)
    end
  end

  def minimum_players?
    self.participants.count >= 4
  end

  def unfinished_players
    self.participants.select do |participant|
      participant.cards_from(self).count < 4
    end
  end

  def cards_added?
    self.unfinished_players.count == 0
  end

  def bowl_empty?
    self.cards.all? do |card|
      !card.in_bowl?
    end
  end

  def count_turns(player)
    self.turns.where(player: player).count
  end

  private

  def initialize_rounds
    RoundType.create_round_types
    3.times do |i|
      self.rounds << Round.new(round_type: RoundType.all[i])
    end
  end

  def next_turn_team
    return self.teams.sample if last_turn_team.nil?
    return self.teams.where.not(name: last_turn_team.name).first
  end

  def last_turn_team
    last_player.teams.where(game: self).first
  end

  def last_player
    self.current_round.last_turn.player || self.players.sample
  end

end<commit_msg>Remove self to move methods to private<commit_after>class Game < ApplicationRecord
  validates :name, presence: true, uniqueness: true

  belongs_to :creator, class_name: User
  has_many :rounds
  has_many :teams
  has_many :turns, through: :rounds
  has_and_belongs_to_many :participants,
                          join_table: "games_participants",
                          class_name: User,
                          association_foreign_key: 'participant_id'

  after_create :initialize_rounds

  def to_param
    name
  end

  def is_over?
    self.rounds.all? { |round| round.is_over? }
  end

  def current_round
    return nil if self.is_over?
    self.rounds.each do |round|
      return round unless round.is_over?
    end
  end

  def get_cluegiver
    next_turn_team.players.shuffle.min_by do |player|
      count_turns(player)
    end
  end

  def minimum_players?
    self.participants.count >= 4
  end

  def unfinished_players
    self.participants.select do |participant|
      participant.cards_from(self).count < 4
    end
  end

  def cards_added?
    self.unfinished_players.count == 0
  end

  def bowl_empty?
    self.cards.all? do |card|
      !card.in_bowl?
    end
  end

  private

  def initialize_rounds
    RoundType.create_round_types
    3.times do |i|
      self.rounds << Round.new(round_type: RoundType.all[i])
    end
  end

  def next_turn_team
    self.teams.where.not(name: last_turn_team.name).first
  end

  def last_turn_team
    return self.teams.sample if last_player.nil?
    last_player.teams.where(game: self).first
  end

  def last_turn
    self.turns.order("created_at").last || Turn.new
  end

  def last_player
    last_turn.player
  end

  def count_turns(player)
    self.turns.where(player: player).count
  end
end
{'fraction_non_alphanumeric': 0.07582260371959942, 'fraction_numerical': 0.0022889842632331904, 'mean_word_length': 2.735042735042735, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6372422', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1170, 'n_words': 266}