Class: Elvarg::Hiscores::Player

Inherits:
Object
  • Object
show all
Includes:
Stats
Defined in:
lib/hiscores/player.rb

Overview

Represents a Player on the Hiscores

Constant Summary

Constants included from Stats

Stats::COMBAT_SKILLS, Stats::MEMBER_SKILLS, Stats::SKILLS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, mode = :default) ⇒ Player

Creates a Player object

Examples:

a Player on the default Hiscores

player = Elvarg::Hiscores::Player.new('ruby')
player.username #=> "ruby"
player.mode #=> :default

a Player on the ironman Hiscores

ironman = Elvarg::Hiscores::Player.new('dids', :ironman)
ironman.username #=> "dids"
ironman.mode #=> :ironman

Parameters:

  • username (String)

    the Player’s username

  • mode (Symbol) (defaults to: :default)

    The mode to search in (default) ‘:default`



51
52
53
54
55
56
57
# File 'lib/hiscores/player.rb', line 51

def initialize(username, mode = :default)
  @username = username
  @mode = mode
  @skills = {}

  parse_data(Hiscores.search_for(username, mode))
end

Instance Attribute Details

#modeSymbol (readonly)

The Hiscore’s mode. This can be :default, :ironman, :ultimate, etc.

Returns:

  • (Symbol)

    The Hiscore’s mode.

See Also:



24
25
26
# File 'lib/hiscores/player.rb', line 24

def mode
  @mode
end

#skillsHash (readonly)

All Stats available in OldSchool Runescape’s Hiscores

Examples:

Information on a Player’s overall skill

player = Elvarg::Hiscores::Player.new 'example'
player.skills #=> { ... } a Hash will all the skills' data
player.skills[:overall] #=> Overall skill

Returns:

  • (Hash)

    All Stats available in OldSchool Runescape’s Hiscores

See Also:



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

def skills
  @skills
end

#usernameString (readonly)

The Player’s username

Examples:

A player named “ruby”

player = Elvarg::Hiscores::Player.new 'ruby'
player.username #=> "ruby"

Returns:

  • (String)

    The Player’s username



18
19
20
# File 'lib/hiscores/player.rb', line 18

def username
  @username
end

Instance Method Details

#free?true, false

Note:

This is the inverse of #member?

Determines if this Player is a free-to-play player.

Examples:

The player, “Ruby”, has trained member’s only skills

player = Elvarg::Hiscores::Player.new 'Ruby'
player.free? #=> false

Returns:

  • (true)

    if the Player only trained free-to-play skills.

  • (false)

    if the Player has trained member’s only skills.

See Also:



87
88
89
# File 'lib/hiscores/player.rb', line 87

def free?
  !member?
end

#member?true, false

Note:

This methods determines member status based on if the Player has trained any member skills.

Determines if this Player is/was a member at one point in time.

Examples:

The player, “Ruby”, has trained member’s only skills

player = Elvarg::Hiscores::Player.new 'Ruby'
player.member? #=> true

Returns:

  • (true)

    if the Player has trained member’s only skills.

  • (false)

    if the Player only trained free-to-play skills.

See Also:



71
72
73
74
# File 'lib/hiscores/player.rb', line 71

def member?
  @skills.each { |_, skill| return true if skill.xp > 0 && skill.member? }
  false
end

#skiller?true, false

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.

Examples:

The player, “Ruby”, is not a skiller

player = Elvarg::Hiscores::Player.new 'Ruby'
player.skiller? #=> false

Returns:

  • (true)
  • (false)


103
104
105
106
107
108
109
# File 'lib/hiscores/player.rb', line 103

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