Class: RsApi::PlayerCompare
- Defined in:
- lib/rs_api/hiscores/player_compare.rb
Overview
class PlayerCompare that compares two PlayerExp skill experience.
Constant Summary
Constants included from SkillHelper
SkillHelper::MAX, SkillHelper::MONTHLY_XP_SKILL_ID_CONST, SkillHelper::SKILL_ID_CONST
Instance Attribute Summary collapse
-
#player1 ⇒ Object
readonly
Returns the value of attribute player1.
-
#player2 ⇒ Object
readonly
Returns the value of attribute player2.
Instance Method Summary collapse
- #compare ⇒ Object
- #display ⇒ Object
-
#initialize(player1, player2) ⇒ PlayerCompare
constructor
A new instance of PlayerCompare.
- #raw_data ⇒ Object
Methods included from PlayerNameHelper
Constructor Details
#initialize(player1, player2) ⇒ PlayerCompare
Returns a new instance of PlayerCompare.
19 20 21 22 |
# File 'lib/rs_api/hiscores/player_compare.rb', line 19 def initialize(player1, player2) @player1 = PlayerExperience.new(player1) @player2 = PlayerExperience.new(player2) end |
Instance Attribute Details
#player1 ⇒ Object (readonly)
Returns the value of attribute player1.
17 18 19 |
# File 'lib/rs_api/hiscores/player_compare.rb', line 17 def player1 @player1 end |
#player2 ⇒ Object (readonly)
Returns the value of attribute player2.
17 18 19 |
# File 'lib/rs_api/hiscores/player_compare.rb', line 17 def player2 @player2 end |
Instance Method Details
#compare ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rs_api/hiscores/player_compare.rb', line 24 def compare SKILL_ID_CONST.each do |key, skill_name| xp_diff = @player1.all_skill_experience[key] - @player2.all_skill_experience[key] raw_data << compare_result(key, skill_name, xp_diff) end end |
#display ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rs_api/hiscores/player_compare.rb', line 32 def display if raw_data.empty? compare table.head = %w[SKILL WINNER LEVEL XP-DIFFERENCE] table.rows = formatted_data end if display? # :nocov: colour? ? (puts colour_table) : (puts table) # :nocov: end table end |
#raw_data ⇒ Object
47 48 49 |
# File 'lib/rs_api/hiscores/player_compare.rb', line 47 def raw_data @raw_data ||= [] # index 0 is total exp, rest is normal skills by exp end |