Skip to content

Commit 850c7bb

Browse files
committed
Adds REGION_DOMAINS for domain mapping to region
1 parent 27054a0 commit 850c7bb

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

lib/bnet_scraper/starcraft2.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ module Starcraft2
1515
'eu' => { domain: 'eu.battle.net', dir: 'eu', label: 'Europe' },
1616
'cn' => { domain: 'www.battlenet.com.cn', dir: 'zh', label: 'China' },
1717
'sea' => { domain: 'sea.battle.net', dir: 'en', label: 'South-East Asia' },
18-
'fea' => { domain: 'tw.battle.net', dir: 'zh', label: 'Korea' }
18+
'fea' => { domain: 'tw.battle.net', dir: 'zh', label: 'Korea' }
19+
}
20+
21+
REGION_DOMAINS = {
22+
'us.battle.net' => 'na',
23+
'eu.battle.net' => 'eu',
24+
'www.battlenet.com.cn' => 'cn',
25+
'sea.battle.net' => 'sea',
26+
'kr.battle.net' => 'fea',
27+
'tw.battle.net' => 'fea'
1928
}
2029

2130
# This is a convenience method that chains calls to ProfileScraper,

lib/bnet_scraper/starcraft2/base_scraper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BaseScraper
2020
def initialize options = {}
2121
if options[:url]
2222
extracted_data = options[:url].match(/http:\/\/(.+)\/sc2\/(.+)\/profile\/(.+)\/(\d{1})\/(.[^\/]+)\//)
23-
@region = REGIONS.select { |k,v| v[:domain] == extracted_data[1] && v[:dir] == extracted_data[2] }.first.first
23+
@region = REGION_DOMAINS[extracted_data[1]]
2424
@bnet_id = extracted_data[3]
2525
@bnet_index = extracted_data[4]
2626
@account = extracted_data[5]
@@ -58,7 +58,7 @@ def profile_url bnet_index = @bnet_index
5858
# converts region short-code to region-based URL information
5959
# 'na' => { domain: 'us.battle.net', :dir: 'en' }
6060
def region_info
61-
REGIONS[region]
61+
REGIONS[region]
6262
end
6363

6464
def valid?

lib/bnet_scraper/starcraft2/status_scraper.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ def method_missing sym
3030
private
3131
def status? region
3232
@status ||= fetch
33-
@status.select do |r|
34-
r[:region] == REGIONS.select { |k,v| k == region.to_s }.first.last[:label]
35-
end.first[:status]
33+
region_status = @status.find do |r|
34+
r[:region] == REGIONS[region.to_s][:label]
35+
end
36+
37+
region_status[:status]
3638
end
3739
end
3840
end

0 commit comments

Comments
 (0)