elvarg 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/elvarg.rb +8 -7
- data/lib/hiscores/hiscores.rb +26 -26
- data/lib/hiscores/player.rb +37 -89
- data/lib/hiscores/skill.rb +25 -0
- data/lib/stats/skill.rb +90 -0
- data/lib/stats/stats.rb +23 -19
- metadata +3 -2
- data/lib/skills/skill.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67e2cce699cff36e9c3449c7c89db0da859d702a3d464e75f78b491636aa1014
|
4
|
+
data.tar.gz: b5da4d18227f1233ba51e7605aa5d51dc245e2a7209528aeaa6aaa675efc4911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59a1de2cd781d6b452c4db7d0497fcd2abc30d6cfa23dd8e1eb0bc3013a15e5cba415d0693c9050652945f910fca00ddb593a8102ba25b8a4e2ea28b48990fda
|
7
|
+
data.tar.gz: 264f3d2466a0780ddff14fcc53f01449d03ce8a1eba2f7fa4d8b94b992ef957f1c982cab3f79ff1565ec19dcdc89f9e7356e1c60064c7edebb5b0493eadc9fb8
|
data/lib/elvarg.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
1
|
+
require_relative 'hiscores/hiscores'
|
2
|
+
require_relative 'hiscores/player'
|
3
|
+
require_relative 'hiscores/skill'
|
4
|
+
require_relative 'stats/skill'
|
5
|
+
require_relative 'stats/stats'
|
5
6
|
|
6
7
|
##
|
7
|
-
# A Ruby Gem that provides useful methods
|
8
|
-
#
|
8
|
+
# A Ruby Gem that provides useful methods
|
9
|
+
# for OldSchool Runescape related applications.
|
9
10
|
#
|
10
|
-
#
|
11
|
+
# @author Marcello Sabino <marchsabino@gmail.com>
|
11
12
|
module Elvarg
|
12
13
|
end
|
data/lib/hiscores/hiscores.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
|
3
|
-
module Elvarg
|
4
|
-
module Hiscores
|
3
|
+
module Elvarg #:nodoc:
|
4
|
+
module Hiscores #:nodoc:
|
5
|
+
##
|
6
|
+
# Represents different modes base URL's on the OldSchool RuneScape Hiscores.
|
5
7
|
MODES = {
|
6
|
-
default:
|
7
|
-
ironman:
|
8
|
-
ultimate:
|
9
|
-
hardcore:
|
10
|
-
deadman:
|
11
|
-
seasonal:
|
12
|
-
tournament:
|
13
|
-
}
|
14
|
-
ENDPOINT = {
|
15
|
-
stats: "index_lite.ws?player=",
|
16
|
-
scores: 'overall.ws?',
|
17
|
-
}
|
8
|
+
default: 'https://secure.runescape.com/m=hiscore_oldschool/',
|
9
|
+
ironman: 'http://services.runescape.com/m=hiscore_oldschool_ironman/',
|
10
|
+
ultimate: 'http://services.runescape.com/m=hiscore_oldschool_ultimate/',
|
11
|
+
hardcore: 'http://services.runescape.com/m=hiscore_oldschool_hardcore_ironman/',
|
12
|
+
deadman: 'http://services.runescape.com/m=hiscore_oldschool_deadman/',
|
13
|
+
seasonal: 'http://services.runescape.com/m=hiscore_oldschool_seasonal/',
|
14
|
+
tournament: 'http://services.runescape.com/m=hiscore_oldschool_tournament/'
|
15
|
+
}.freeze
|
18
16
|
|
19
17
|
##
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
#
|
18
|
+
# Represents different endpoints on the Hiscores.
|
19
|
+
ENDPOINTS = {
|
20
|
+
stats: 'index_lite.ws?player=',
|
21
|
+
scores: 'overall.ws?'
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
##
|
25
|
+
# Searches for a particular player on the Hiscores and grabs data
|
26
|
+
# about the player.
|
29
27
|
#
|
30
|
-
#
|
31
|
-
#
|
28
|
+
# @param username [String] the player's username
|
29
|
+
# @param mode [Symbol] the mode to grab data in.
|
30
|
+
# This can be any of the Elvarg::Hiscores::MODES.
|
31
|
+
# @return [String] data about the Player on the Hiscores
|
32
32
|
def self.search_for(username, mode = :default)
|
33
|
-
open(MODES[mode] +
|
33
|
+
open(MODES[mode] + ENDPOINTS[:stats] + username, &:read)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
data/lib/hiscores/player.rb
CHANGED
@@ -1,119 +1,67 @@
|
|
1
|
-
require_relative './hiscores'
|
2
1
|
require_relative '../stats/stats'
|
3
|
-
require_relative '
|
2
|
+
require_relative './hiscores'
|
3
|
+
require_relative './skill'
|
4
4
|
|
5
|
-
module Elvarg
|
6
|
-
module Hiscores
|
5
|
+
module Elvarg #:nodoc:
|
6
|
+
module Hiscores #:nodoc:
|
7
7
|
##
|
8
|
-
# Represents a
|
9
|
-
class Player
|
8
|
+
# Represents a Player on the Hiscores
|
9
|
+
class Player
|
10
|
+
include Elvarg::Stats
|
10
11
|
attr_reader :username
|
11
12
|
attr_reader :mode
|
12
13
|
attr_reader :skills
|
13
14
|
|
14
15
|
##
|
15
|
-
# Creates a
|
16
|
-
#
|
17
|
-
# ==== Parameters
|
18
|
-
#
|
19
|
-
# * [String] +username+ - The user's username
|
20
|
-
# * [Symbol] +mode+ - The mode to search in. see +Hiscores::MODES+, defaults to +:default+
|
16
|
+
# Creates a Player object
|
21
17
|
#
|
22
|
-
#
|
18
|
+
# @example a Player on the default Hiscores
|
19
|
+
# player = Elvarg::Hiscores::Player.new('ruby')
|
20
|
+
# player.username #=> "ruby"
|
21
|
+
# player.mode #=> :default
|
22
|
+
# @example a Player on the ironman Hiscores
|
23
|
+
# ironman = Elvarg::Hiscores::Player.new('dids', :ironman)
|
24
|
+
# ironman.username #=> "dids"
|
25
|
+
# ironman.mode #=> :ironman
|
23
26
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# # Search through the ultimate ironman hiscores
|
27
|
-
# player = Elvarg::Hiscores::Player.new('ruby', :ultimate)
|
27
|
+
# @param username [String] the Player's username
|
28
|
+
# @param mode [Symbol] The mode to search in (default) `:default`
|
28
29
|
def initialize(username, mode = :default)
|
29
30
|
@username = username
|
30
31
|
@mode = mode
|
31
32
|
@skills = {}
|
32
33
|
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
##
|
37
|
-
# Determines if this player is a member
|
38
|
-
#
|
39
|
-
# ==== Details
|
40
|
-
#
|
41
|
-
# This detects membership if the user has greater than 0 experience in
|
42
|
-
# any member's only skill.
|
43
|
-
#
|
44
|
-
# ==== Returns
|
45
|
-
#
|
46
|
-
# [true] if the player has experience in a member's only skill, false otherwise
|
47
|
-
#
|
48
|
-
# ==== Examples
|
49
|
-
#
|
50
|
-
# player = Elvarg::Hiscores::Player.new 'ruby'
|
51
|
-
# player.is_member?
|
52
|
-
# #=> true
|
53
|
-
def is_member?
|
54
|
-
@skills.each { |key, skill| return true if skill.xp > 0 && skill.is_member? }
|
55
|
-
false
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# The inverse of +is_member?+
|
60
|
-
def is_free?
|
61
|
-
!is_member?
|
62
|
-
end
|
63
|
-
|
64
|
-
##
|
65
|
-
# Determines if this player is a skiller
|
66
|
-
# A user is a skiller when they do not have any combat skill
|
67
|
-
# (other than 10 hitpoints) greater than 1.
|
68
|
-
#
|
69
|
-
# ==== Returns
|
70
|
-
#
|
71
|
-
# [true] if the player has 1 in all combat skills (and 10 hitpoints) false otherwise
|
72
|
-
#
|
73
|
-
# ==== Examples
|
74
|
-
#
|
75
|
-
# player = Elvarg::Hiscores::Player.new 'ruby'
|
76
|
-
# player.is_skiller?
|
77
|
-
# #=> false
|
78
|
-
def is_skiller?
|
79
|
-
@skills.each { |key, skill|
|
80
|
-
next if key == :hitpoints && skill.level <= 10
|
81
|
-
return false if skill.level > 1 && skill.is_combat?
|
82
|
-
}
|
83
|
-
true
|
34
|
+
parse_data(Hiscores.search_for(username, mode))
|
84
35
|
end
|
85
36
|
|
86
37
|
private
|
87
38
|
|
88
39
|
##
|
89
|
-
#
|
90
|
-
# creates an array so that we can work with the data.
|
40
|
+
# Parses the data that's grabbed from RuneScape.
|
91
41
|
#
|
92
|
-
#
|
93
|
-
|
94
|
-
|
95
|
-
def extract(data)
|
96
|
-
hiscores_data = []
|
42
|
+
# @param data [String] the data grabbed from RuneScape.
|
43
|
+
def parse_data(data)
|
44
|
+
hiscore_data = []
|
97
45
|
data.split("\n").each { |skill|
|
98
|
-
|
46
|
+
hiscore_data.push(skill.split(',').map(&:to_i))
|
99
47
|
}
|
100
48
|
|
101
|
-
extract_skills
|
49
|
+
extract_skills(hiscore_data)
|
102
50
|
end
|
103
51
|
|
104
52
|
##
|
105
|
-
# Extracts only the
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
i
|
115
|
-
|
116
|
-
|
53
|
+
# Extracts only the skill data from the hiscore data.
|
54
|
+
#
|
55
|
+
# @param hiscore_data [Array] Skill data from the Hiscores in an array
|
56
|
+
def extract_skills(hiscore_data)
|
57
|
+
SKILLS.each_with_index do |skill, i|
|
58
|
+
@skills[skill] = Skill.new(
|
59
|
+
skill, i,
|
60
|
+
hiscore_data[i][0],
|
61
|
+
hiscore_data[i][1],
|
62
|
+
hiscore_data[i][2]
|
63
|
+
)
|
64
|
+
end
|
117
65
|
end
|
118
66
|
end
|
119
67
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../stats/skill'
|
2
|
+
|
3
|
+
module Elvarg #:nodoc:
|
4
|
+
module Hiscores #:nodoc:
|
5
|
+
##
|
6
|
+
# Represents a Skill on the Hiscores
|
7
|
+
class Skill < Stats::Skill
|
8
|
+
# TODO
|
9
|
+
attr_reader :rank
|
10
|
+
# TODO
|
11
|
+
attr_reader :level
|
12
|
+
# TODO
|
13
|
+
attr_reader :exp
|
14
|
+
|
15
|
+
##
|
16
|
+
# TODO
|
17
|
+
def initialize(symbol, id = 0, rank = -1, level = 1, exp = 0)
|
18
|
+
super(symbol, id)
|
19
|
+
@rank = rank
|
20
|
+
@level = level
|
21
|
+
@exp = exp
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/stats/skill.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require_relative './stats'
|
2
|
+
|
3
|
+
module Elvarg #:nodoc:
|
4
|
+
module Stats
|
5
|
+
##
|
6
|
+
# Represents a Skill in OldSchool RuneScape
|
7
|
+
class Skill
|
8
|
+
# The link to the `.gif` of the related Skill
|
9
|
+
attr_reader :icon
|
10
|
+
# The unique id of this Skill
|
11
|
+
attr_reader :id
|
12
|
+
# The human readable name of this Skill
|
13
|
+
attr_reader :name
|
14
|
+
##
|
15
|
+
# The symbol of this Skill
|
16
|
+
# @see Elvarg::Stats::SKILLS for list of symbols
|
17
|
+
attr_reader :symbol
|
18
|
+
|
19
|
+
##
|
20
|
+
# Creates a new Skill object.
|
21
|
+
#
|
22
|
+
# @example Create a Hunter Skill object
|
23
|
+
# hunter = Elvarg::Stats::Skill.new(:hunter, 22)
|
24
|
+
# hunter.level #=> 1
|
25
|
+
# @example Create a Hitpoints Skill object
|
26
|
+
# hitpoints = Elvarg::Stats::Skill.new(:hitpoints, 4)
|
27
|
+
# hitpoints.level #=> 10
|
28
|
+
# @example Create a Runecraft Skill, with no id will default to 0
|
29
|
+
# runecraft = Elvarg::Stats::Skill.new(:runecraft)
|
30
|
+
# runecraft.level #=> 1
|
31
|
+
# runecraft.id #=> 0
|
32
|
+
#
|
33
|
+
# @param symbol [Symbol] the symbol of this skill.
|
34
|
+
# @param id [Integer] the unique identifier of this skill, 1 is attack.
|
35
|
+
# (0).
|
36
|
+
def initialize(symbol, id = 0)
|
37
|
+
@id = id
|
38
|
+
@symbol = symbol
|
39
|
+
@name = symbol.to_s.capitalize
|
40
|
+
@icon = 'https://www.runescape.com/img/rsp777/' \
|
41
|
+
"hiscores/skill_icon_#{@name.downcase}1.gif"
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Determines if this Skill is a member's only skill.
|
46
|
+
#
|
47
|
+
# @example Slayer is a member's only skill.
|
48
|
+
# Elvarg::Stats::Skill.new(:hunter).members? #=> true
|
49
|
+
# @example Runecraft is a free-to-play skill.
|
50
|
+
# Elvarg::Stats::Skill.new(:runecraft).members? #=> false
|
51
|
+
# @return [true] if this Skill is a member's only skill.
|
52
|
+
# @return [false] if this Skill is free-to-play.
|
53
|
+
def members?
|
54
|
+
MEMBER_SKILLS.include? @symbol
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Determines if this Skill is a free-to-play skill.
|
59
|
+
#
|
60
|
+
# @note This is the inverse of `members?`
|
61
|
+
# @see members?
|
62
|
+
def free?
|
63
|
+
!members?
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Determines if this Skill will affect a player's combat
|
68
|
+
#
|
69
|
+
# @example Attack will affect one's combat level
|
70
|
+
# Elvarg::Stats::Skill.new(:attack).combat? #=> true
|
71
|
+
# @example Woodcutting will not affect one's combat level
|
72
|
+
# Elvarg::Stats::Skill.new(:woodcutting).combat? #=> false
|
73
|
+
#
|
74
|
+
# @return [true] if this Skill affects a player's combat
|
75
|
+
# @return [false] if this Skill does not affect a player's combat
|
76
|
+
def combat?
|
77
|
+
COMBAT_SKILLS.include? @symbol
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Determines if this Skill does not affect a player's combat
|
82
|
+
#
|
83
|
+
# @note This is the inverse of `combat?`
|
84
|
+
# @see combat?
|
85
|
+
def skiller_friendly?
|
86
|
+
!combat?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/stats/stats.rb
CHANGED
@@ -1,27 +1,31 @@
|
|
1
1
|
module Elvarg
|
2
|
-
module Stats
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
module Stats #:nodoc:
|
3
|
+
##
|
4
|
+
# An array of symbols that represent all
|
5
|
+
# available skills on OldSchool RuneScape.
|
6
|
+
SKILLS = %i[
|
7
|
+
overall attack defence strength
|
8
|
+
hitpoints ranged prayer magic
|
9
|
+
cooking woodcutting fletching fishing
|
10
|
+
firemaking crafting smithing mining
|
11
|
+
herblore agility thieving slayer
|
9
12
|
farming runecraft hunter construction
|
10
|
-
|
11
|
-
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
##
|
16
|
+
# An array of symbols that represent all skills
|
17
|
+
# that are member's only.
|
18
|
+
MEMBER_SKILLS = %i[
|
12
19
|
fletching herblore agility thieving
|
13
20
|
slayer farming hunter construction
|
14
|
-
|
15
|
-
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
##
|
24
|
+
# An array of symbols that represent all skills
|
25
|
+
# that affect a player's combat level.
|
26
|
+
COMBAT_SKILLS = %i[
|
16
27
|
attack defence strength hitpoints
|
17
28
|
ranged prayer magic
|
18
|
-
|
19
|
-
MINIGAMES = %i(
|
20
|
-
bounty_hunter bounty_rogue
|
21
|
-
)
|
22
|
-
CLUES = %i(
|
23
|
-
all easy medium hard
|
24
|
-
elite master
|
25
|
-
)
|
29
|
+
].freeze
|
26
30
|
end
|
27
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elvarg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcello A. Sabino
|
@@ -20,7 +20,8 @@ files:
|
|
20
20
|
- lib/elvarg.rb
|
21
21
|
- lib/hiscores/hiscores.rb
|
22
22
|
- lib/hiscores/player.rb
|
23
|
-
- lib/
|
23
|
+
- lib/hiscores/skill.rb
|
24
|
+
- lib/stats/skill.rb
|
24
25
|
- lib/stats/stats.rb
|
25
26
|
homepage: https://github.com/marchsabino/Elvarg
|
26
27
|
licenses:
|
data/lib/skills/skill.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require_relative '../stats/stats'
|
2
|
-
|
3
|
-
module Elvarg
|
4
|
-
class Skill include Stats
|
5
|
-
attr_reader :id
|
6
|
-
attr_reader :symbol
|
7
|
-
attr_reader :name
|
8
|
-
attr_reader :rank
|
9
|
-
attr_reader :level
|
10
|
-
attr_reader :xp
|
11
|
-
attr_reader :icon
|
12
|
-
|
13
|
-
##
|
14
|
-
# Creates a new Skill object
|
15
|
-
#
|
16
|
-
# Paramters:
|
17
|
-
# [Symbol] symbol - The symbol of the skill, like :attack, :magic, :ranged
|
18
|
-
# [Integer] rank - The user's rank. Default is -1
|
19
|
-
# [Integer] level - The user's level in this skill. Default is 1
|
20
|
-
# [Integer] xp - The user's experience in this skill. Default is 0
|
21
|
-
# [Integer] id - The id of this skill, default is -1
|
22
|
-
def initialize(symbol, rank = -1, level = 1, xp = 0, id = -1)
|
23
|
-
@id = id
|
24
|
-
@symbol = symbol
|
25
|
-
@name = symbol.to_s.capitalize
|
26
|
-
@rank = rank
|
27
|
-
@level = level
|
28
|
-
@level = 10 if level == 1 && symbol == :hitpoints
|
29
|
-
@xp = xp
|
30
|
-
@xp = 1154 if xp == 0 && symbol == :hitpoints
|
31
|
-
@icon = "https://www.runescape.com/img/rsp777/hiscores/skill_icon_#{@name.downcase}1.gif"
|
32
|
-
end
|
33
|
-
|
34
|
-
##
|
35
|
-
# Determines if this Skill is a member's only skill
|
36
|
-
#
|
37
|
-
# Returns:
|
38
|
-
# true - if this skill is member's only, false otherwise
|
39
|
-
def is_member?
|
40
|
-
Stats::MEMBER_SKILLS.include? @symbol
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# Determines if this Skill is a free to play skill
|
45
|
-
# The inverse of `is_member?`
|
46
|
-
def is_free?
|
47
|
-
!is_member?
|
48
|
-
end
|
49
|
-
|
50
|
-
##
|
51
|
-
# Determines if this Skill will affect a user's combat level
|
52
|
-
#
|
53
|
-
# Returns:
|
54
|
-
# true - if this skill will affect combat level, false otherwise
|
55
|
-
def is_combat?
|
56
|
-
Stats::COMBAT_SKILLS.include? @symbol
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# Determines if this Skill is skiller friendly
|
61
|
-
# The inverse of `is_combat?`
|
62
|
-
def is_skiller_friendly?
|
63
|
-
!combat?
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|