class Elvarg::Hiscores::Player
Attributes
The Hiscore's mode. This can be :default, :ironman, :ultimate, etc.
@see Hiscores::MODES for complete list @return [Symbol] The Hiscore's mode.
All Stats
available in OldSchool Runescape's Hiscores
@example Information on a Player's overall skill
player = Elvarg::Hiscores::Player.new 'example' player.skills #=> { ... } a Hash with all the skills' data player.skills[:overall] #=> Overall skill
@see Elvarg::Stats::SKILLS Complete list of skills @see Elvarg::Hiscores::Skill
@return [Hash<Symbol, Elvarg::Hiscores::Skill>] All Stats
available in
OldSchool Runescape's Hiscores
The Player's username
@example A player named “ruby”
player = Elvarg::Hiscores::Player.new 'ruby' player.username #=> "ruby"
@return [String] The Player's username
Public Class Methods
Creates a Player
object
@example a Player
on the default Hiscores
player = Elvarg::Hiscores::Player.new('ruby') player.username #=> "ruby" player.mode #=> :default
@example a Player
on the ironman Hiscores
ironman = Elvarg::Hiscores::Player.new('dids', :ironman) ironman.username #=> "dids" ironman.mode #=> :ironman
@param username [String] the Player's username @param mode [Symbol] The mode to search in (default) `:default`
# File lib/hiscores/player.rb, line 52 def initialize(username, mode = :default) @username = username @mode = mode @skills = {} parse_data(Hiscores.search_for(username, mode)) end
Public Instance Methods
Determines if this Player
is a free-to-play player.
@example The player, “Ruby”, has trained member's only skills
player = Elvarg::Hiscores::Player.new 'Ruby' player.free? #=> false
@note This is the inverse of member?
@see member? @return [true] if the Player
only trained free-to-play skills. @return [false] if the Player
has trained member's only skills.
# File lib/hiscores/player.rb, line 88 def free? !member? end
Determines if this Player
is/was a member at one point in time.
@example The player, “Ruby”, has trained member's only skills
player = Elvarg::Hiscores::Player.new 'Ruby' player.member? #=> true
@note This methods determines member status based on if the Player
has trained any member skills.
@see free? @return [true] if the Player
has trained member's only skills. @return [false] if the Player
only trained free-to-play skills.
# File lib/hiscores/player.rb, line 72 def member? @skills.each { |_, skill| return true if skill.xp > 0 && skill.member? } false end
Determines if this Player
is a skiller (combat level 3).
If a Player
has any combat level > 1 (with the exception of 10 hitpoints) that Player
is classified as a Skiller.
@example The player, “Ruby”, is not a skiller
player = Elvarg::Hiscores::Player.new 'Ruby' player.skiller? #=> false
@return [true] @return [false]
# File lib/hiscores/player.rb, line 104 def skiller? @skills.each do |key, skill| next if key == :hitpoints && skill.level <= 10 return false if skill.level > 1 && skill.combat? end true end
Private Instance Methods
Extracts only the skill data from the hiscore data.
@param hiscore_data [Array] Skill
data from the Hiscores
in an array
# File lib/hiscores/player.rb, line 131 def extract_skills(hiscore_data) SKILLS.each_with_index do |skill, i| @skills[skill] = Skill.new( skill, i, hiscore_data[i][0], hiscore_data[i][1], hiscore_data[i][2] ) end end
Parses the data that's grabbed from RuneScape.
@param data [String] the data grabbed from RuneScape.
# File lib/hiscores/player.rb, line 118 def parse_data(data) hiscore_data = [] data.split("\n").each { |skill| hiscore_data.push(skill.split(',').map(&:to_i)) } extract_skills(hiscore_data) end