Class: HoN::MatchStats
- Inherits:
-
Stats
- Object
- Stats
- HoN::MatchStats
show all
- Defined in:
- lib/honclient/match_stats.rb
Instance Attribute Summary
Attributes inherited from Stats
#stats
Instance Method Summary
collapse
Methods inherited from Stats
#error, #error?, #method_missing, #nickname, #stat
Constructor Details
#initialize(match_id) ⇒ MatchStats
Returns a new instance of MatchStats.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/honclient/match_stats.rb', line 3
def initialize(match_id)
@match_id = match_id
@summary_stats = {}
@team_one_stats = {}
@team_two_stats = {}
@team_one_players = []
@team_two_players = []
begin
url = "http://xml.heroesofnewerth.com/xml_requester.php?f=match_stats&opt=mid&mid[]=#{@match_id}"
xml_data = Net::HTTP.get_response(URI.parse(url)).body
data = Nokogiri::XML.parse(xml_data)
data.xpath('//xmlRequest/stats/match/summ/stat').each do |stat|
@summary_stats[stat["name"]] = stat.content
end
data.xpath("//xmlRequest/stats/match/team[@side=1]/stat").each do |stat|
@team_one_stats[stat["name"]] = stat.content
end
data.xpath("//xmlRequest/stats/match/team[@side=2]/stat").each do |stat|
@team_two_stats[stat["name"]] = stat.content
end
data.xpath("//xmlRequest/stats/match/match_stats/ms").each do |ms|
temp = {}
team = 0
ms.children.each do |stat|
if stat["name"] == "team"
team = stat.content.to_i
end
temp[stat["name"]] = stat.content
end
if team == 1
@team_one_players.push(temp)
else
@team_two_players.push(temp)
end
end
rescue SocketError
@error = "Could not contact the Newerth XML API."
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class HoN::Stats
Instance Method Details
#dump_xml_stats ⇒ Object
76
77
78
|
# File 'lib/honclient/match_stats.rb', line 76
def dump_xml_stats
return @summary_stats, @team_one_stats, @team_two_stats, @team_one_players
end
|
#match_id ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/honclient/match_stats.rb', line 48
def match_id
if defined? @match_id
@match_id
else
nil
end
end
|
#summary_stats(key) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/honclient/match_stats.rb', line 55
def summary_stats(key)
if @summary_stats.has_key? key
@summary_stats[key]
else
return 0
end
end
|
#team_one ⇒ Object
42
43
44
|
# File 'lib/honclient/match_stats.rb', line 42
def team_one
@team_one_players
end
|
#team_one_stats(key) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/honclient/match_stats.rb', line 62
def team_one_stats(key)
if @team_one_stats.has_key? key
@team_one_stats[key]
else
return 0
end
end
|
#team_two ⇒ Object
45
46
47
|
# File 'lib/honclient/match_stats.rb', line 45
def team_two
@team_two_players
end
|
#team_two_stats(key) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/honclient/match_stats.rb', line 69
def team_two_stats(key)
if @team_two_stats.has_key? key
@team_two_stats[key]
else
return 0
end
end
|