elvarg 0.0.0 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elvarg.rb +9 -1
- data/lib/hiscores/hiscores.rb +36 -0
- data/lib/hiscores/player.rb +120 -0
- data/lib/skills/skill.rb +66 -0
- data/lib/stats/stats.rb +27 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f996173667b01d63eb1fc686c3ab1567e39756d552de283926a1501dccd6008d
|
4
|
+
data.tar.gz: ed61f3c8fad382a412ba1bf9d9f65d63b90ef8dfc84ea077725de369964d464b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 215449333501c3ef8c79b114c08c2439a197ea17f61a835b776f872ea27719c1080a39503c358b9d989ae605a0682e9dea960ca2d9a1acad08d487e22fa55e7c
|
7
|
+
data.tar.gz: 2b2788d9b646573f48c27c40c07af33016c75fa81bfbb03fd01603811398130e7d2f9a2b6d1f884ecedb800d5d516cfdc7d55409512b32875007d122c996d3e1
|
data/lib/elvarg.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
+
require_relative "stats/stats"
|
2
|
+
require_relative "skills/skill"
|
3
|
+
require_relative "hiscores/player"
|
4
|
+
require_relative "hiscores/hiscores"
|
5
|
+
|
1
6
|
##
|
2
|
-
#
|
7
|
+
# A Ruby Gem that provides useful methods for OldSchool
|
8
|
+
# RuneScape related applications.
|
9
|
+
#
|
10
|
+
# Author: Marcello A. Sabino
|
3
11
|
module Elvarg
|
4
12
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Elvarg # :nodoc:
|
4
|
+
module Hiscores
|
5
|
+
MODES = {
|
6
|
+
default: "https://secure.runescape.com/m=hiscore_oldschool/",
|
7
|
+
ironman: "http://services.runescape.com/m=hiscore_oldschool_ironman/",
|
8
|
+
ultimate: "http://services.runescape.com/m=hiscore_oldschool_ultimate/",
|
9
|
+
hardcore: "http://services.runescape.com/m=hiscore_oldschool_hardcore_ironman/",
|
10
|
+
deadman: "http://services.runescape.com/m=hiscore_oldschool_deadman/",
|
11
|
+
seasonal: "http://services.runescape.com/m=hiscore_oldschool_seasonal/",
|
12
|
+
tournament: "http://services.runescape.com/m=hiscore_oldschool_tournament/",
|
13
|
+
}
|
14
|
+
ENDPOINT = {
|
15
|
+
stats: "index_lite.ws?player=",
|
16
|
+
scores: 'overall.ws?',
|
17
|
+
}
|
18
|
+
|
19
|
+
##
|
20
|
+
# Searches for a specific user on a specified mode on the OldSchool
|
21
|
+
# RuneScape HiScores website.
|
22
|
+
#
|
23
|
+
# ==== Parameters
|
24
|
+
#
|
25
|
+
# * [String] +username+ - The user's username
|
26
|
+
# * [Symbol] +mode+ - the mode to look in, see Hiscores::MODES for available modes. Default is `:default`.
|
27
|
+
#
|
28
|
+
# ==== Examples
|
29
|
+
#
|
30
|
+
# player = Elvarg::Hiscores.search_for 'ruby'
|
31
|
+
# player = Elvarg::Hiscores.search_for('github', :ironman)
|
32
|
+
def self.search_for(username, mode = :default)
|
33
|
+
open(MODES[mode] + ENDPOINT[:stats] + username, &:read)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require_relative './hiscores'
|
2
|
+
require_relative '../stats/stats'
|
3
|
+
require_relative '../skills/skill'
|
4
|
+
|
5
|
+
module Elvarg
|
6
|
+
module Hiscores
|
7
|
+
##
|
8
|
+
# Represents a single player on OldSchool Runescape
|
9
|
+
class Player include Hiscores, Stats
|
10
|
+
attr_reader :username
|
11
|
+
attr_reader :mode
|
12
|
+
attr_reader :skills
|
13
|
+
|
14
|
+
##
|
15
|
+
# Creates a new Player object
|
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+
|
21
|
+
#
|
22
|
+
# ==== Examples
|
23
|
+
#
|
24
|
+
# # Search through the default overall hiscores
|
25
|
+
# player = Elvarg::Hiscores::Player.new 'ruby'
|
26
|
+
# # Search through the ultimate ironman hiscores
|
27
|
+
# player = Elvarg::Hiscores::Player.new('ruby', :ultimate)
|
28
|
+
def initialize(username, mode = :default)
|
29
|
+
@username = username
|
30
|
+
@mode = mode
|
31
|
+
@skills = {}
|
32
|
+
|
33
|
+
extract(Hiscores.search_for(username, mode))
|
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
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
##
|
89
|
+
# Extracts the data from the OldSchool RuneScape HiScores API and
|
90
|
+
# creates an array so that we can work with the data.
|
91
|
+
#
|
92
|
+
# Parameters:
|
93
|
+
# [String] data - The HiScores data from
|
94
|
+
# the OldSchool Runescape HiScores API
|
95
|
+
def extract(data)
|
96
|
+
hiscores_data = []
|
97
|
+
data.split("\n").each { |skill|
|
98
|
+
hiscores_data.push(skill.split(',').map(&:to_i))
|
99
|
+
}
|
100
|
+
|
101
|
+
extract_skills hiscores_data
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Extracts only the skills' data from the hiscores array
|
106
|
+
def extract_skills(hiscores_data)
|
107
|
+
i = 0
|
108
|
+
SKILLS.each { |skill|
|
109
|
+
@skills[skill] = Elvarg::Skill.new(
|
110
|
+
skill,
|
111
|
+
hiscores_data[i][0],
|
112
|
+
hiscores_data[i][1],
|
113
|
+
hiscores_data[i][2],
|
114
|
+
i)
|
115
|
+
i += 1
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/lib/skills/skill.rb
ADDED
@@ -0,0 +1,66 @@
|
|
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
|
data/lib/stats/stats.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Elvarg
|
2
|
+
module Stats
|
3
|
+
SKILLS = %i(
|
4
|
+
overall attack defence strength
|
5
|
+
hitpoints ranged prayer magic
|
6
|
+
cooking woodcutting fletching fishing
|
7
|
+
firemaking crafting smithing mining
|
8
|
+
herblore agility thieving slayer
|
9
|
+
farming runecraft hunter construction
|
10
|
+
)
|
11
|
+
MEMBER_SKILLS = %i(
|
12
|
+
fletching herblore agility thieving
|
13
|
+
slayer farming hunter construction
|
14
|
+
)
|
15
|
+
COMBAT_SKILLS = %i(
|
16
|
+
attack defence strength hitpoints
|
17
|
+
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
|
+
)
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcello A. Sabino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby Gem that provides useful methods for OldSchool RuneScape related
|
14
14
|
applications.
|
@@ -18,6 +18,10 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/elvarg.rb
|
21
|
+
- lib/hiscores/hiscores.rb
|
22
|
+
- lib/hiscores/player.rb
|
23
|
+
- lib/skills/skill.rb
|
24
|
+
- lib/stats/stats.rb
|
21
25
|
homepage: https://github.com/marchsabino/Elvarg
|
22
26
|
licenses:
|
23
27
|
- MIT
|
@@ -41,5 +45,5 @@ rubyforge_project:
|
|
41
45
|
rubygems_version: 2.7.6
|
42
46
|
signing_key:
|
43
47
|
specification_version: 4
|
44
|
-
summary:
|
48
|
+
summary: A Ruby Gem with useful methods for OldSchool Runescape related applications.
|
45
49
|
test_files: []
|