Class: EhbrsRubyUtils::Bga::GameStatistics::WhatsappFormatter::PlayerContent

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs_ruby_utils/bga/game_statistics/whatsapp_formatter/player_content.rb

Instance Method Summary collapse

Instance Method Details

#rank_label(rank) ⇒ String

Parameters:

  • rank (Integer)

Returns:

  • (String)


22
23
24
# File 'lib/ehbrs_ruby_utils/bga/game_statistics/whatsapp_formatter/player_content.rb', line 22

def rank_label(rank)
  "#{rank}ยบ"
end

#rank_percent(count) ⇒ String

Parameters:

  • count (Integer)

Returns:

  • (String)


40
41
42
# File 'lib/ehbrs_ruby_utils/bga/game_statistics/whatsapp_formatter/player_content.rb', line 40

def rank_percent(count)
  (count * 100 / formatter.normal_tables.count).round
end

#rank_value(rank) ⇒ String

Parameters:

  • rank (Integer)

Returns:

  • (String)


28
29
30
31
32
33
34
35
36
# File 'lib/ehbrs_ruby_utils/bga/game_statistics/whatsapp_formatter/player_content.rb', line 28

def rank_value(rank)
  count = 0
  formatter.normal_tables.each do |table|
    count += 1 if table.player_by_id(player.id).if_present(false) do |v|
                    v.rank == rank
                  end
  end
  "#{count} (#{rank_percent(count)}%)"
end

#resultHash<String, String>

Returns:

  • (Hash<String, String>)


14
15
16
17
18
# File 'lib/ehbrs_ruby_utils/bga/game_statistics/whatsapp_formatter/player_content.rb', line 14

def result
  formatter.ranks.to_h do |rank|
    [rank_label(rank), rank_value(rank)]
  end
end