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`



34
35
36
37
38
39
40
# File 'lib/hiscores/player.rb', line 34

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

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

Instance Attribute Details

#modeObject (readonly)

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

See Also:



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

def mode
  @mode
end

#skillsObject (readonly)

A Hash of all Stats available in OldSchool Runescape’s Hiscores



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

def skills
  @skills
end

#usernameObject (readonly)

The Player’s username



12
13
14
# File 'lib/hiscores/player.rb', line 12

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:



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

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:



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

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)


86
87
88
89
90
91
92
# File 'lib/hiscores/player.rb', line 86

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