rshighscores 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/lib/rshighscores/oldschool.rb +58 -0
- data/lib/rshighscores/player.rb +1 -3
- data/lib/rshighscores/stats.rb +9 -11
- data/lib/rshighscores.rb +6 -2
- data/spec/lookup_spec.rb +4 -4
- data/spec/oldschool_spec.rb +25 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c3fb91c10bab6b714839776d3c8c425d59ad2fa
|
4
|
+
data.tar.gz: f2d47f6a1cc8b731ec416bfdeab69111b3bcb7fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6610d92a3acf36c1b0bf51f190d1ccfe423bcabaab11d80a8d6b13b265ed0006cfc5da28dde6d460d7834435431d388353adb3144991a827982cf4a8b942bac8
|
7
|
+
data.tar.gz: 39b637cb3057ab22a2ed0de7fb68be13d009dd48ffce723565100989535279649b51fcd9fe05aac12a90b84ff3da8bf0ad47abf4c288488eccce4da5f9ee496c
|
data/README.md
CHANGED
@@ -6,11 +6,7 @@ Easy to use gem for downloading and parsing Runescape highscores. Inspired to so
|
|
6
6
|
|
7
7
|
## Rename and compatibility changes
|
8
8
|
|
9
|
-
This gem was previously called `osrshighscores` and only worked with Oldschool Runescape. The current version has been renamed to reflect the future version-agnostic highscore parsing that the gem will do.
|
10
|
-
|
11
|
-
### But what if I want the Oldschool Runescape version?
|
12
|
-
|
13
|
-
Don't worry, it's still around. It currently resides in its own branch, `version-1` and will still function as before. I intend to merge the two versions later on for ease of development and use so keep an eye out for version 3.x.
|
9
|
+
This gem was previously called `osrshighscores` and only worked with Oldschool Runescape. The current version has been renamed to reflect the future version-agnostic highscore parsing that the gem will do. As of version 2.1.0, Oldschool Runescape is supported alongside Runescape 3. There are aliases in place to make code from 1.x work without issue in 2.1.x onwards, so if you were using 1.x you need not change anything.
|
14
10
|
|
15
11
|
### Why the change at all?
|
16
12
|
|
@@ -28,16 +24,20 @@ And then execute:
|
|
28
24
|
|
29
25
|
Or install it yourself as:
|
30
26
|
|
31
|
-
$ gem install
|
27
|
+
$ gem install rshighscores
|
32
28
|
|
33
29
|
## Usage
|
34
30
|
|
35
31
|
```ruby
|
36
32
|
require 'rshighscores'
|
37
33
|
|
38
|
-
|
39
|
-
highscores =
|
34
|
+
foot = RsHighscores::Player.new "Foot"
|
35
|
+
highscores = foot.stats
|
40
36
|
puts highscores.hunter.level # => 99
|
37
|
+
|
38
|
+
jebrim = OSRS::Player.new "Jebrim" # RsHighscores::OldSchool::Player would work too
|
39
|
+
highscores = jebrim.stats
|
40
|
+
puts highscores.agility.level # => 99
|
41
41
|
```
|
42
42
|
|
43
43
|
## Contributing
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module RsHighscores
|
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
|
+
class Stats < RsHighscores::Stats
|
13
|
+
Skills = %w(Overall Attack Defence Strength
|
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)
|
19
|
+
|
20
|
+
ExpectedStatCount = 39
|
21
|
+
ActualStatCount = 23
|
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
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module OSRS
|
56
|
+
Player = RsHighscores::OldSchool::Player
|
57
|
+
Stats = RsHighscores::OldSchool::Stats
|
58
|
+
end
|
data/lib/rshighscores/player.rb
CHANGED
@@ -2,8 +2,6 @@ require 'open-uri'
|
|
2
2
|
|
3
3
|
module RsHighscores
|
4
4
|
class Player
|
5
|
-
@@lookup_url = "http://hiscore.runescape.com/index_lite.ws?player="
|
6
|
-
|
7
5
|
attr_reader :name, :raw_stats, :stats
|
8
6
|
|
9
7
|
def initialize name, force = :no_force
|
@@ -23,7 +21,7 @@ module RsHighscores
|
|
23
21
|
end
|
24
22
|
|
25
23
|
def fetch_highscores
|
26
|
-
f = open(
|
24
|
+
f = open("http://hiscore.runescape.com/index_lite.ws?player=" + @name, "User-Agent" => "Ruby/RsHighscoresGrabber")
|
27
25
|
|
28
26
|
@raw_stats = f.readlines.map &:chomp # readlines preserves newlines??
|
29
27
|
@stats = RsHighscores::Stats.new @raw_stats
|
data/lib/rshighscores/stats.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module RsHighscores
|
2
2
|
class Stats
|
3
|
-
|
3
|
+
Skills = %w(Overall Attack Defence Strength
|
4
4
|
Hitpoints Ranged Prayer Magic
|
5
5
|
Cooking Woodcutting Fletching Fishing
|
6
6
|
Firemaking Crafting Smithing Mining
|
@@ -8,24 +8,26 @@ module RsHighscores
|
|
8
8
|
Farming Runecrafting Hunter Construction
|
9
9
|
Summoning Dungeoneering Divination)
|
10
10
|
|
11
|
+
ExpectedStatCount = 44
|
12
|
+
ActualStatCount = 27
|
13
|
+
|
11
14
|
attr_accessor :stats, :raw_stats
|
12
15
|
|
13
16
|
def initialize raw_stats
|
14
|
-
@expected_stat_count = 44
|
15
17
|
@raw_stats = raw_stats
|
16
18
|
|
17
19
|
parse_stats
|
18
20
|
end
|
19
21
|
|
20
22
|
def validate_raw_stats
|
21
|
-
raise "incorrect input length" unless @raw_stats.length ==
|
23
|
+
raise "incorrect input length" unless @raw_stats.length == ExpectedStatCount
|
22
24
|
end
|
23
25
|
|
24
26
|
def parse_stats
|
25
27
|
validate_raw_stats
|
26
28
|
|
27
29
|
@stats = []
|
28
|
-
@raw_stats.take(
|
30
|
+
@raw_stats.take(ActualStatCount).each do |line|
|
29
31
|
raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/
|
30
32
|
stat = line.split(",").map(&:to_i)
|
31
33
|
|
@@ -46,19 +48,15 @@ module RsHighscores
|
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
|
-
def skill_names
|
50
|
-
@@skills
|
51
|
-
end
|
52
|
-
|
53
51
|
def [] skill
|
54
52
|
skill = skill.to_s.capitalize
|
55
|
-
raise "non-existant skill lookup" unless
|
53
|
+
raise "non-existant skill lookup" unless Skills.index(skill)
|
56
54
|
|
57
|
-
stats[
|
55
|
+
stats[Skills.index(skill)]
|
58
56
|
end
|
59
57
|
|
60
58
|
def method_missing name, *args
|
61
|
-
return self[name] if
|
59
|
+
return self[name] if Skills.include? name.to_s.capitalize
|
62
60
|
raise NoMethodError
|
63
61
|
end
|
64
62
|
end
|
data/lib/rshighscores.rb
CHANGED
data/spec/lookup_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe RsHighscores::Stats do
|
|
32
32
|
|
33
33
|
describe "stat parsing" do
|
34
34
|
it "parsed output length" do
|
35
|
-
@stats.stats.length.should eq(
|
35
|
+
@stats.stats.length.should eq(RsHighscores::Stats::Skills.count)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "stats in groups of three" do
|
@@ -72,13 +72,13 @@ describe RsHighscores::Stats do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it "success on valid skill lookup" do
|
75
|
-
|
75
|
+
RsHighscores::Stats::Skills.each do |name|
|
76
76
|
@stats[name].should be_a(Array)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
it "skill_names output" do
|
81
|
-
|
81
|
+
RsHighscores::Stats::Skills.should eq(%w(Overall Attack Defence Strength
|
82
82
|
Hitpoints Ranged Prayer Magic
|
83
83
|
Cooking Woodcutting Fletching Fishing
|
84
84
|
Firemaking Crafting Smithing Mining
|
@@ -94,7 +94,7 @@ describe RsHighscores::Stats do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it "missing method call" do
|
97
|
-
|
97
|
+
RsHighscores::Stats::Skills.each do |name|
|
98
98
|
@stats.send(name.downcase).should eq(@stats[name])
|
99
99
|
end
|
100
100
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RsHighscores::OldSchool::Player do
|
4
|
+
context "backwards compatibility" do
|
5
|
+
it "namespace alias" do
|
6
|
+
OSRS::Player.should eq(RsHighscores::OldSchool::Player)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context "usability" do
|
11
|
+
before :all do
|
12
|
+
@player = OSRS::Player.new "jebrim", :force
|
13
|
+
@stats = OSRS::Stats.new @player.raw_stats
|
14
|
+
end
|
15
|
+
|
16
|
+
it "skill_names output" do
|
17
|
+
OSRS::Stats::Skills.should eq(%w(Overall Attack Defence Strength
|
18
|
+
Hitpoints Ranged Prayer Magic
|
19
|
+
Cooking Woodcutting Fletching Fishing
|
20
|
+
Firemaking Crafting Smithing Mining
|
21
|
+
Herblore Agility Thieving Slayer
|
22
|
+
Farming Runecrafting Hunter Construction))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
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.0
|
4
|
+
version: 2.1.0
|
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-
|
12
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -82,10 +82,12 @@ files:
|
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
84
|
- lib/rshighscores.rb
|
85
|
+
- lib/rshighscores/oldschool.rb
|
85
86
|
- lib/rshighscores/player.rb
|
86
87
|
- lib/rshighscores/stats.rb
|
87
88
|
- rshighscores.gemspec
|
88
89
|
- spec/lookup_spec.rb
|
90
|
+
- spec/oldschool_spec.rb
|
89
91
|
- spec/player_spec.rb
|
90
92
|
- spec/spec_helper.rb
|
91
93
|
homepage: https://github.com/sambooo/OSRSGrabber
|
@@ -114,5 +116,6 @@ specification_version: 4
|
|
114
116
|
summary: RS Highscore Parser
|
115
117
|
test_files:
|
116
118
|
- spec/lookup_spec.rb
|
119
|
+
- spec/oldschool_spec.rb
|
117
120
|
- spec/player_spec.rb
|
118
121
|
- spec/spec_helper.rb
|