rshighscores 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rshighscores.rb +2 -2
- data/lib/rshighscores/oldschool.rb +6 -44
- data/lib/rshighscores/player.rb +5 -2
- data/lib/rshighscores/stats.rb +4 -4
- data/rshighscores.gemspec +1 -1
- data/spec/oldschool_spec.rb +15 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65715b1d02915366ec42ac21a14426e2af3dc4e2
|
4
|
+
data.tar.gz: 045218ae68c4899ad5885dc2d9b1cdd0093ebb80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94bdf04ea1cbc42499029f6315f0413435af5b05bfd4304d6fc5b7c8a7a65db74d9f6921be90394c22ad0f4e221387cbfa1c3bdc62f0535bcd5259d2dd2e41a9
|
7
|
+
data.tar.gz: 77265f8db8e0aff161ff466fd32de31eaad7f9975b3eb504c7155556dd3349f5794fa409850bb5a407e8b988a9acb2b7b2eb114f5a4e37e9b751b827519294cc
|
data/lib/rshighscores.rb
CHANGED
@@ -1,53 +1,15 @@
|
|
1
1
|
module RsHighscores
|
2
2
|
module OldSchool
|
3
|
-
class Player < RsHighscores::Player
|
4
|
-
def fetch_highscores
|
5
|
-
f = open("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=" + @name, "User-Agent" => "Ruby/RsHighscoresGrabber")
|
6
|
-
|
7
|
-
@raw_stats = f.readlines.map &:chomp # readlines preserves newlines??
|
8
|
-
@stats = RsHighscores::OldSchool::Stats.new @raw_stats
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
3
|
class Stats < RsHighscores::Stats
|
13
|
-
Skills =
|
14
|
-
Hitpoints Ranged Prayer Magic
|
15
|
-
Cooking Woodcutting Fletching Fishing
|
16
|
-
Firemaking Crafting Smithing Mining
|
17
|
-
Herblore Agility Thieving Slayer
|
18
|
-
Farming Runecrafting Hunter Construction)
|
4
|
+
Skills = RsHighscores::Stats::Skills.take(24)
|
19
5
|
|
20
6
|
ExpectedStatCount = 39
|
21
|
-
ActualStatCount =
|
22
|
-
|
23
|
-
def validate_raw_stats
|
24
|
-
raise "incorrect input length" unless @raw_stats.length == ExpectedStatCount
|
25
|
-
end
|
26
|
-
|
27
|
-
def parse_stats
|
28
|
-
validate_raw_stats
|
29
|
-
|
30
|
-
@stats = []
|
31
|
-
@raw_stats.take(ActualStatCount).each do |line|
|
32
|
-
raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/
|
33
|
-
stat = line.split(",").map(&:to_i)
|
34
|
-
|
35
|
-
class << stat
|
36
|
-
def method_missing name, *args
|
37
|
-
case name
|
38
|
-
when :rank
|
39
|
-
return self[0]
|
40
|
-
when :level
|
41
|
-
return self[1]
|
42
|
-
when :xp
|
43
|
-
return self[2]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
@stats << stat
|
49
|
-
end
|
7
|
+
ActualStatCount = 24
|
50
8
|
end
|
9
|
+
|
10
|
+
class Player < RsHighscores::Player
|
11
|
+
LookupUrl = "http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player="
|
12
|
+
StatClass = RsHighscores::OldSchool::Stats
|
51
13
|
end
|
52
14
|
end
|
53
15
|
end
|
data/lib/rshighscores/player.rb
CHANGED
@@ -2,6 +2,9 @@ require 'open-uri'
|
|
2
2
|
|
3
3
|
module RsHighscores
|
4
4
|
class Player
|
5
|
+
LookupUrl = "http://hiscore.runescape.com/index_lite.ws?player="
|
6
|
+
StatClass = RsHighscores::Stats
|
7
|
+
|
5
8
|
attr_reader :name, :raw_stats, :stats
|
6
9
|
|
7
10
|
def initialize name, force = :no_force
|
@@ -21,10 +24,10 @@ module RsHighscores
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def fetch_highscores
|
24
|
-
f = open(
|
27
|
+
f = open(self.class::LookupUrl + @name, "User-Agent" => "Ruby/RsHighscoresGrabber")
|
25
28
|
|
26
29
|
@raw_stats = f.readlines.map &:chomp # readlines preserves newlines??
|
27
|
-
@stats =
|
30
|
+
@stats = self.class::StatClass.new @raw_stats
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
data/lib/rshighscores/stats.rb
CHANGED
@@ -20,14 +20,14 @@ module RsHighscores
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def validate_raw_stats
|
23
|
-
raise "incorrect input length" unless @raw_stats.length == ExpectedStatCount
|
23
|
+
raise "incorrect input length" unless @raw_stats.length == self.class::ExpectedStatCount
|
24
24
|
end
|
25
25
|
|
26
26
|
def parse_stats
|
27
27
|
validate_raw_stats
|
28
28
|
|
29
29
|
@stats = []
|
30
|
-
@raw_stats.take(ActualStatCount).each do |line|
|
30
|
+
@raw_stats.take(self.class::ActualStatCount).each do |line|
|
31
31
|
raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/
|
32
32
|
stat = line.split(",").map(&:to_i)
|
33
33
|
|
@@ -50,9 +50,9 @@ module RsHighscores
|
|
50
50
|
|
51
51
|
def [] skill
|
52
52
|
skill = skill.to_s.capitalize
|
53
|
-
raise "non-existant skill lookup" unless Skills.index(skill)
|
53
|
+
raise "non-existant skill lookup" unless self.class::Skills.index(skill)
|
54
54
|
|
55
|
-
stats[Skills.index(skill)]
|
55
|
+
stats[self.class::Skills.index(skill)]
|
56
56
|
end
|
57
57
|
|
58
58
|
def method_missing name, *args
|
data/rshighscores.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["sam@26th-zerk.co.uk"]
|
11
11
|
spec.description = %q{Easy to use gem for downloading and parsing Runescape highscores}
|
12
12
|
spec.summary = %q{RS Highscore Parser}
|
13
|
-
spec.homepage = "https://github.com/sambooo/
|
13
|
+
spec.homepage = "https://github.com/sambooo/RsHighscores"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/spec/oldschool_spec.rb
CHANGED
@@ -21,5 +21,20 @@ describe RsHighscores::OldSchool::Player do
|
|
21
21
|
Herblore Agility Thieving Slayer
|
22
22
|
Farming Runecrafting Hunter Construction))
|
23
23
|
end
|
24
|
+
|
25
|
+
it "individual skill lookup" do
|
26
|
+
@stats.stats.each do |stat|
|
27
|
+
stat.should be_a(Array)
|
28
|
+
stat.each do |elem|
|
29
|
+
elem.should be_a(Numeric)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "named stat lookup" do
|
35
|
+
OSRS::Stats::Skills.each do |skill|
|
36
|
+
@stats.send(skill.to_sym).should be_a(Array)
|
37
|
+
end
|
38
|
+
end
|
24
39
|
end
|
25
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rshighscores
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Broughton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -90,7 +90,7 @@ files:
|
|
90
90
|
- spec/oldschool_spec.rb
|
91
91
|
- spec/player_spec.rb
|
92
92
|
- spec/spec_helper.rb
|
93
|
-
homepage: https://github.com/sambooo/
|
93
|
+
homepage: https://github.com/sambooo/RsHighscores
|
94
94
|
licenses:
|
95
95
|
- MIT
|
96
96
|
metadata: {}
|