battlenet_info 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/battlenet_info.rb +25 -2
- metadata +2 -2
data/lib/battlenet_info.rb
CHANGED
@@ -13,9 +13,9 @@ class BattleNetInfo
|
|
13
13
|
@ladder_url = "#{@profile_url}#{splitter}ladder/leagues"
|
14
14
|
end
|
15
15
|
|
16
|
+
# <b>DEPRECATED:</b> Now calls from each method if needed
|
16
17
|
def download_data
|
17
|
-
|
18
|
-
download_ladder_content
|
18
|
+
warn "[DEPRECATION] `download_data` is deprecated. Now calls from each method if needed."
|
19
19
|
end
|
20
20
|
|
21
21
|
def valid_url?
|
@@ -35,18 +35,21 @@ class BattleNetInfo
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def achievement_points
|
38
|
+
download_profile_content if self.profile_content.empty?
|
38
39
|
match_data = /<h3>(?<achievement_points>\d+)<\/h3>/i.match self.profile_content
|
39
40
|
|
40
41
|
match_data[:achievement_points].to_i
|
41
42
|
end
|
42
43
|
|
43
44
|
def race
|
45
|
+
download_profile_content if self.profile_content.empty?
|
44
46
|
match_data = /class=\Wrace-(?<race>\w+)\W/i.match self.profile_content
|
45
47
|
|
46
48
|
match_data[:race]
|
47
49
|
end
|
48
50
|
|
49
51
|
def stats
|
52
|
+
download_ladder_content if self.ladder_content.empty?
|
50
53
|
match_data = /<div\s+class=\Wtooltip-title\W>#{self.player_name}<\/div>[\n\t\s]+<strong>[\w\s]+\W<\/strong>\s*\d+<br\s*\/>[\t\n\s]+<strong>[\w\s]+\W\s*<\/strong>\s*\w+\s*<\/div>[\t\n\s]+<\/td>[\t\n\s]+<td\sclass=\Walign-center\W>(?<points>\d+)<\/td>[\t\n\s]+<td\sclass=\Walign-center\W>(?<wins>\d+)<\/td>/mi.match self.ladder_content
|
51
54
|
|
52
55
|
return [0, 0] if match_data.nil?
|
@@ -54,6 +57,7 @@ class BattleNetInfo
|
|
54
57
|
end
|
55
58
|
|
56
59
|
def rank
|
60
|
+
download_ladder_content if self.ladder_content.empty?
|
57
61
|
match_data = /<td\s+class=\Walign-center\W\sstyle=\Wwidth:\s40px\W>(?<rank>\d+)\W*\w+<\/td>[\n\t\s]+<td>[\n\t\s]+<a\shref=\W\/sc2\/\w+\/profile\/\d+\/\d\/#{self.player_name}/mi.match self.ladder_content
|
58
62
|
|
59
63
|
return 0 if match_data.nil?
|
@@ -61,6 +65,7 @@ class BattleNetInfo
|
|
61
65
|
end
|
62
66
|
|
63
67
|
def league
|
68
|
+
download_profile_content if self.profile_content.empty?
|
64
69
|
expr = /badge-(?<league>\w+)\sbadge-medium-(?<top>\d+)\W>\s+<\/span>\s+<\/a>\s+<div\sid=\Wbest-team-1/im
|
65
70
|
match_data = expr.match self.profile_content
|
66
71
|
|
@@ -68,11 +73,29 @@ class BattleNetInfo
|
|
68
73
|
end
|
69
74
|
|
70
75
|
def portrait_html_style(new_path)
|
76
|
+
download_profile_content if self.profile_content.empty?
|
71
77
|
match_data = /<span\s+class=\Wicon-frame\s+\W[\s\t\n]+(?<picture_style>\w+\=[\w\s\W]+portraits[\w\s\W]+90px;)\W>[\t\n\s]+<\/span>/im.match self.profile_content
|
72
78
|
|
73
79
|
match_data[:picture_style].sub('/sc2/static/local-common/images/sc2/portraits/', new_path)
|
74
80
|
end
|
75
81
|
|
82
|
+
def to_hash
|
83
|
+
points, wins = self.stats
|
84
|
+
|
85
|
+
player_data = {
|
86
|
+
:server => self.server,
|
87
|
+
:player_name => self.player_name,
|
88
|
+
:achievement_points => self.achievement_points,
|
89
|
+
:race => self.race,
|
90
|
+
:points => points,
|
91
|
+
:wins => wins,
|
92
|
+
:rank => self.rank,
|
93
|
+
:league => self.league
|
94
|
+
}
|
95
|
+
|
96
|
+
player_data
|
97
|
+
end
|
98
|
+
|
76
99
|
private
|
77
100
|
|
78
101
|
def download_profile_content
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: battlenet_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,7 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/battlenet_info.rb
|
21
|
-
homepage:
|
21
|
+
homepage: https://github.com/ck3g/battlenet_info
|
22
22
|
licenses: []
|
23
23
|
post_install_message:
|
24
24
|
rdoc_options: []
|