Class: QuakeliveApi::Parser::Summary
- Inherits:
-
Base
- Object
- Base
- QuakeliveApi::Parser::Summary
show all
- Defined in:
- lib/quakelive_api/parser/summary.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #invalid_player?, #request_error?
Instance Method Details
#accuracy ⇒ Object
43
44
45
|
# File 'lib/quakelive_api/parser/summary.rb', line 43
def accuracy
vitals.at(selector(:accuracy)).next.text.match(/([\d.]+)%/)[1].to_f
end
|
#awards ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/quakelive_api/parser/summary.rb', line 65
def awards
awards = document.css(selector(:awards)).map do |node|
title = node.at('.vcenter_data b')
next if title.text =~ /No recent award/
info = node['title']
icon = node.at('img')['src']
awarded = title.next.next
description = awarded.next.next
Items::Award.new(icon, info, title.text.strip, awarded.text.strip, description.text.strip.gsub("\n",""))
end.compact
awards.any? ? awards : nil
end
|
#clan ⇒ Object
13
14
15
16
|
# File 'lib/quakelive_api/parser/summary.rb', line 13
def clan
clan_tag = document.at(selector(:clan))
clan_tag.text if clan_tag
end
|
#country ⇒ Object
5
6
7
|
# File 'lib/quakelive_api/parser/summary.rb', line 5
def country
document.at(selector(:country))['title']
end
|
#favourites ⇒ Object
59
60
61
62
63
|
# File 'lib/quakelive_api/parser/summary.rb', line 59
def favourites
Items::Favourite.new(*document.css(selector(:favs))
.map { |n| n.next.text.strip }
.map { |n| n == "None" ? nil : n })
end
|
#frags_deaths ⇒ Object
51
52
53
|
# File 'lib/quakelive_api/parser/summary.rb', line 51
def frags_deaths
parse_slashed vitals.at(selector(:frags))
end
|
#hits_shots ⇒ Object
55
56
57
|
# File 'lib/quakelive_api/parser/summary.rb', line 55
def hits_shots
parse_slashed vitals.at(selector(:hits))
end
|
#last_game ⇒ Object
29
30
31
32
|
# File 'lib/quakelive_api/parser/summary.rb', line 29
def last_game
node = vitals.at selector(:last)
decode_time(node['title']) if node
end
|
#losses_quits ⇒ Object
47
48
49
|
# File 'lib/quakelive_api/parser/summary.rb', line 47
def losses_quits
parse_slashed vitals.at(selector(:losses))
end
|
#member_since ⇒ Object
25
26
27
|
# File 'lib/quakelive_api/parser/summary.rb', line 25
def member_since
Date.parse vitals.at(selector(:member)).next.text.match(/([\w.\s,]+)/)[1]
end
|
#model ⇒ Object
18
19
20
21
22
23
|
# File 'lib/quakelive_api/parser/summary.rb', line 18
def model
div = document.at(selector(:model))
name = div['title']
image = decode_background(div['style'])
Items::Model.new(name, image)
end
|
#nick ⇒ Object
9
10
11
|
# File 'lib/quakelive_api/parser/summary.rb', line 9
def nick
document.at(selector(:nick)).xpath('text()').text.strip
end
|
#recent_competitors ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/quakelive_api/parser/summary.rb', line 95
def recent_competitors
competitors = document.css(selector(:competitors)).map do |node|
next if node.at('.rcmp_none')
icon = decode_background node.at('.usericon_standard_lg')['style']
nick = node.at('a.player_nick_dark').xpath('child::text()').to_s
played = decode_time(node.at('span.text_tooltip')['title'])
Items::Competitor.new(icon, nick, played )
end.compact
competitors if competitors.any?
end
|
#recent_games ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/quakelive_api/parser/summary.rb', line 82
def recent_games
games = document.css(selector(:games)).map do |node|
gametype = decode_gametype node.at('img.gametype')['src']
finish = node.at('span.finish').text.strip.match(/Finish:\s+(\w+)/i)[1]
played = node.at('span.played').text.strip.match(/Played:\s+([\w ]+)/i)[1]
image = node.at('img.levelshot')['src']
Items::RecentGame.new(gametype, finish, played, image)
end.compact
games if games.any?
end
|
#time_played ⇒ Object
34
35
36
37
|
# File 'lib/quakelive_api/parser/summary.rb', line 34
def time_played
node = vitals.at selector(:played)
GameTime.new(node['title']) if node
end
|
#wins ⇒ Object
39
40
41
|
# File 'lib/quakelive_api/parser/summary.rb', line 39
def wins
to_integer vitals.at(selector(:wins)).next.text
end
|