Skip to content

Commit dc2f0b2

Browse files
committed
Adds Current Solo League / Highest Solo League
1 parent f036721 commit dc2f0b2

File tree

4 files changed

+144
-62
lines changed

4 files changed

+144
-62
lines changed

lib/bnet_scraper/starcraft2/profile_scraper.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ module Starcraft2
2222
# }
2323
class ProfileScraper < BaseScraper
2424
attr_reader :achievement_points, :career_games, :race, :leagues, :most_played,
25-
:games_this_season
25+
:games_this_season, :highest_solo_league, :current_solo_league
26+
27+
def initialize options = {}
28+
super
29+
@leagues = []
30+
end
31+
2632
def scrape
2733
get_profile_data
2834
get_league_list
@@ -42,6 +48,15 @@ def get_profile_data
4248
@career_games = html.css(".stat-block:nth-child(3) h2").inner_html()
4349
@most_played = html.css(".stat-block:nth-child(2) h2").inner_html()
4450
@games_this_season = html.css(".stat-block:nth-child(1) h2").inner_html()
51+
52+
if solo_league_finishes = html.css("#best-finish-SOLO div")[0]
53+
@highest_solo_league = html.css("#best-finish-SOLO div")[0].children[2].inner_text.strip
54+
@current_solo_league = html.css("#best-finish-SOLO div")[0].children[8].inner_text.strip
55+
else
56+
@highest_solo_league = "Unranked"
57+
@current_solo_league = "Unranked"
58+
end
59+
4560
else
4661
raise BnetScraper::InvalidProfileError
4762
end
@@ -71,6 +86,8 @@ def output
7186
account: @account,
7287
bnet_index: @bnet_index,
7388
race: @race,
89+
current_solo_league: @current_solo_league,
90+
highest_solo_league: @highest_solo_league,
7491
career_games: @career_games,
7592
games_this_season: @games_this_season,
7693
most_played: @most_played,

spec/starcraft2/profile_scraper_spec.rb

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
describe '#get_profile_data' do
1212
it 'should set the race, wins, and achievements attributes' do
13-
subject.instance_variable_get(:@race).should be_nil
14-
subject.instance_variable_get(:@achievement_points).should be_nil
13+
subject.race.should be_nil
14+
subject.achievement_points.should be_nil
1515

1616
subject.get_profile_data
1717

18-
subject.instance_variable_get(:@race).should == 'Protoss'
19-
subject.instance_variable_get(:@achievement_points).should == '3660'
18+
subject.race.should == 'Protoss'
19+
subject.achievement_points.should == '3660'
2020
end
2121
end
2222

2323
describe 'get_league_list' do
2424
it 'should set an array of leagues' do
25-
subject.instance_variable_get(:@leagues).should be_nil
25+
subject.should have(0).leagues
2626
subject.get_league_list
2727

2828
subject.instance_variable_get(:@leagues).should have(12).leagues
@@ -57,10 +57,6 @@
5757
before do
5858
scraper.scrape
5959
end
60-
61-
it 'should set nil race' do
62-
scraper.race.should == ''
63-
end
6460

6561
it 'should have an empty array of leagues' do
6662
scraper.leagues.should == []
@@ -77,73 +73,88 @@
7773
race: 'Protoss',
7874
career_games: '1568',
7975
games_this_season: '0',
76+
highest_solo_league: 'Platinum',
77+
current_solo_league: 'Not Yet Ranked',
8078
most_played: '4v4',
8179
achievement_points: '3660',
8280
leagues: [
8381
{
84-
name: "1v1 Platinum Rank 95",
85-
id: "96905",
82+
name: "1v1 Platinum Rank 95",
83+
id: "96905",
8684
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/96905#current-rank"
87-
},
85+
},
8886
{
89-
name: "2v2 Random Platinum ...",
90-
id: "96716",
87+
name: "2v2 Random Platinum ...",
88+
id: "96716",
9189
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/96716#current-rank"
9290
},
9391
{
9492
name: "2v2 Diamond Rank 45",
95-
id: "98162",
93+
id: "98162",
9694
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/98162#current-rank"
97-
},
95+
},
9896
{
9997
name: "2v2 Silver Rank 8",
100-
id: "97369",
98+
id: "97369",
10199
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/97369#current-rank"
102100
},
103101
{
104102
name: "3v3 Random Gold Rank...",
105-
id: "96828",
103+
id: "96828",
106104
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/96828#current-rank"
107-
},
105+
},
108106
{
109107
name: "3v3 Diamond Rank 56",
110-
id: "97985",
108+
id: "97985",
111109
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/97985#current-rank"
112-
},
110+
},
113111
{
114112
name: "3v3 Silver Rank 5",
115-
id: "98523",
113+
id: "98523",
116114
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/98523#current-rank"
117115
},
118116
{
119-
name: "3v3 Platinum Rank 88",
120-
id: "96863",
117+
name: "3v3 Platinum Rank 88",
118+
id: "96863",
121119
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/96863#current-rank"
122120
},
123121
{
124-
name: "3v3 Gold Rank 75",
125-
id: "97250",
122+
name: "3v3 Gold Rank 75",
123+
id: "97250",
126124
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/97250#current-rank"
127125
},
128126
{
129127
name: "4v4 Random Platinum ...",
130-
id: "96830",
128+
id: "96830",
131129
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/96830#current-rank"
132130
},
133131
{
134132
name: "4v4 Gold Rank 38",
135-
id: "98336",
133+
id: "98336",
136134
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/98336#current-rank"
137135
},
138136
{
139137
name: "4v4 Diamond Rank 54",
140-
id: "98936",
138+
id: "98936",
141139
href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/98936#current-rank"
142-
}
140+
}
143141
]
144142
}
145143

146-
subject.output.should == { bnet_id: '2377239', account: 'Demon', bnet_index: 1, race: nil, career_games: nil, games_this_season: nil, most_played: nil, achievement_points: nil, leagues: nil }
144+
subject.output.should == {
145+
bnet_id: '2377239',
146+
account: 'Demon',
147+
bnet_index: 1,
148+
race: nil,
149+
career_games: nil,
150+
games_this_season: nil,
151+
most_played: nil,
152+
highest_solo_league: nil,
153+
current_solo_league: nil,
154+
achievement_points: nil,
155+
leagues: []
156+
}
157+
147158
subject.scrape
148159
subject.output.should == expected
149160
end

spec/starcraft2_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
:career_games => '1568',
1212
:games_this_season => '0',
1313
:most_played => '4v4',
14+
:current_solo_league => 'Not Yet Ranked',
15+
:highest_solo_league => 'Platinum',
1416
:achievement_points=>"3660",
1517
:leagues=>[
1618
{:season=>"6", :size=>"4v4", :name=>"Aleksander Pepper", :division=>"Diamond", :random=>false, :bnet_id=>"2377239", :account=>"Demon"},

spec/support/no_ladder.html

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ <h1 id="logo"><a href="/sc2/en/">Battle.net</a></h1>
125125
<a href="/sc2/en/" rel="np">
126126
StarCraft II
127127
</a>
128+
<span class="breadcrumb-arrow"></span>
128129
</li>
129130
<li class="last">
130131
<a href="/sc2/en/profile/3354437/1/ClarkeKent/" rel="np">
@@ -230,54 +231,96 @@ <h3>35</h3>
230231
<div id="profile-right">
231232

232233
<div class="profile-module">
234+
233235
<div class="module-top">
234236
<div class="module-bot">
235237
<div class="module-left" id="season-snapshot">
236238
<div class="module-title">
237-
<h3 class="title-globe">
238-
Season 8 <span>-</span>
239-
Snapshot
240-
</h3>
239+
<h3 class="title-globe">Player Stats</h3>
241240
</div>
242241

242+
<div class="module-body snapshot-terran">
243+
244+
<div class="stat-block">
245+
<h3>Games Played This Season</h3>
246+
<h2>0</h2>
247+
</div>
248+
249+
<div class="stat-block">
250+
<h3>Most Played Mode</h3>
251+
<h2>1v1</h2>
252+
</div>
253+
254+
<div class="stat-block">
255+
<h3>Total Career Games</h3>
256+
<h2>2</h2>
257+
</div>
258+
259+
<div class="stat-block">
260+
<h3>Most Played Race</h3>
261+
<h2 class="race">Terran</h2>
262+
</div>
243263

244-
<div class="module-body snapshot-empty">
245-
<h3>No games have been played.</h3>
246264
</div>
247265
</div>
248266

249267
<div class="module-right" id="career-stats">
250-
<div class="module-title">
251-
<h3 class="title-graph">Career Stats</h3>
252-
</div>
268+
<div class="module-title"></div>
253269

270+
<div class="module-body">
271+
254272

255273

256-
<div class="module-body campaign-unearned">
257-
<h4>League Wins</h4>
258-
<h2>0</h2>
259274

260-
<br />
261-
<h4>Games Won</h4>
262-
263-
<ul>
264-
<li>
265-
<span>0</span>
266-
Custom Games
267-
</li>
268-
<li>
269-
<span>0</span>
270-
FFA
271-
</li>
272-
<li>
273-
<span>0</span>
274-
Co-Op vs AI
275-
</li>
276-
</ul>
275+
<div class="badge-item" data-tooltip="#best-finish-SOLO">
276+
277+
<div class="badge">
278+
279+
<span class="badge badge-none badge-medium-1">
280+
</span>
281+
</div>
282+
<div class="mode">1V1</div>
283+
<div class="league-name">
284+
No Career Finishes
285+
</div>
286+
287+
<div id="best-finish-SOLO" style="display: none">
288+
Not Yet Ranked
289+
</div>
290+
</div>
291+
292+
293+
294+
295+
296+
<div class="badge-item" data-tooltip="#best-finish-TEAM">
297+
298+
<div class="badge">
299+
300+
<span class="badge badge-none badge-medium-1">
301+
</span>
302+
</div>
303+
<div class="mode">TEAM</div>
304+
<div class="league-name">
305+
No Career Finishes
306+
</div>
307+
308+
<div id="best-finish-TEAM" style="display: none">
309+
Not Yet Ranked
310+
</div>
311+
</div>
277312

278313
<br />
279314

280-
<h4>Campaign Not Complete</h4>
315+
316+
317+
<div class="badge-item campaign">
318+
<div class="badge unearned"></div>
319+
<div class="mode">Wings of Liberty</div>
320+
<div class="rank">Campaign Not Complete</div>
321+
</div>
322+
323+
<span class="clear"><!-- --></span>
281324
</div>
282325
</div>
283326

@@ -880,10 +923,18 @@ <h2 class="explore-caption">More</h2>
880923
</script>
881924
<script type="text/javascript" src="/sc2/static/local-common/js/menu.js?v42"></script>
882925
<script type="text/javascript" src="/sc2/static/js/sc2.js?v21"></script>
926+
<!--[if IE 6]> <script type="text/javascript" src="/sc2/static/local-common/js/third-party/DD_belatedPNG.js?v42"></script>
927+
<script type="text/javascript">
928+
//<![CDATA[
929+
DD_belatedPNG.fix('.icon');
930+
//]]>
931+
</script>
932+
<![endif]-->
883933
<script type="text/javascript">
884934
//<![CDATA[
885935
$(function(){
886936
Menu.initialize('/data/menu.json?v42');
937+
Search.initialize('/sc2/en/search/ta');
887938
Tooltip.options.useTable = true;
888939
});
889940
//]]>
@@ -913,3 +964,4 @@ <h2 class="explore-caption">More</h2>
913964
</script>
914965
</body>
915966
</html>
967+

0 commit comments

Comments
 (0)