Class: RsApi::PlayerCompare

Inherits:
Hiscore
  • Object
show all
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

Instance Method Summary collapse

Methods included from PlayerNameHelper

check_player_name

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

#player1Object (readonly)

Returns the value of attribute player1.



17
18
19
# File 'lib/rs_api/hiscores/player_compare.rb', line 17

def player1
  @player1
end

#player2Object (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

#compareObject



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

#displayObject



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_dataObject



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