Class: RsApi::PlayerExperience

Inherits:
Hiscore
  • Object
show all
Defined in:
lib/rs_api/hiscores/player_experience.rb

Overview

Class PlayerExp pulls, from Hiscores, player level/experience in each skill.

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(player_name) ⇒ PlayerExperience

Returns a new instance of PlayerExperience.



18
19
20
21
# File 'lib/rs_api/hiscores/player_experience.rb', line 18

def initialize(player_name)
  PlayerNameHelper.check_player_name(player_name)
  @player_name = player_name
end

Instance Attribute Details

#player_nameObject (readonly)

Returns the value of attribute player_name.



16
17
18
# File 'lib/rs_api/hiscores/player_experience.rb', line 16

def player_name
  @player_name
end

#table_resultsObject (readonly)

Returns the value of attribute table_results.



16
17
18
# File 'lib/rs_api/hiscores/player_experience.rb', line 16

def table_results
  @table_results
end

Instance Method Details

#all_skill_experienceObject



52
53
54
55
56
# File 'lib/rs_api/hiscores/player_experience.rb', line 52

def all_skill_experience
  # Retuns array containing the experience for each skill
  # Index of skills corresponds to RsConst::SKILL_ID_CONST
  raw_data.map { |n| n.last.delete(',').to_i }
end

#displayObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rs_api/hiscores/player_experience.rb', line 23

def display
  fill_table_data if table.rows.empty?
  if display?
    # :nocov:
    colour? ? (puts colour_table) : (puts table)
    # :nocov:
  end
  table
rescue RsApi::RsRequest::PlayerNotFound
  puts "#{@player_name} does not exist.".red if display?
end

#max_skill_levelObject



39
40
41
42
# File 'lib/rs_api/hiscores/player_experience.rb', line 39

def max_skill_level
  # Returns the highest skill level out of all sklls
  raw_data[1..].map { |value| value[1].to_i }.max.to_s
end

#raw_dataObject



35
36
37
# File 'lib/rs_api/hiscores/player_experience.rb', line 35

def raw_data
  @raw_data ||= parsed[0..29]
end

#skills_at_max_levelObject



44
45
46
47
48
49
50
# File 'lib/rs_api/hiscores/player_experience.rb', line 44

def skills_at_max_level
  # Returns a array containing only skills at max_skill_level
  # SKILL_ID_CONST[i+1] | i is +1 because I don't want to load the overall skill totals
  raw_data[1..].filter_map.with_index do |value, i|
    SKILL_ID_CONST[i + 1].to_s.capitalize if value[1] == max_skill_level
  end
end