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)


20
21
22
# File 'lib/ehbrs_ruby_utils/bga/game_statistics/whatsapp_formatter/player_content.rb', line 20

def rank_label(rank)
  "#{rank}º"
end

#rank_percent(count) ⇒ String

Parameters:

  • count (Integer)

Returns:

  • (String)


38
39
40
# File 'lib/ehbrs_ruby_utils/bga/game_statistics/whatsapp_formatter/player_content.rb', line 38

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

#rank_value(rank) ⇒ String

Parameters:

  • rank (Integer)

Returns:

  • (String)


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

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>)


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

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