lib/quakelive_api/parser/summary.rb in quakelive_api-0.0.1 vs lib/quakelive_api/parser/summary.rb in quakelive_api-0.1.0
- old
+ new
@@ -5,15 +5,16 @@
def country
document.at(selector(:country))['title']
end
def nick
- document.at(selector(:nick)).text
+ document.at(selector(:nick)).xpath('text()').text.strip
end
def clan
- (c = document.at(selector(:clan))) ? c.text : nil
+ clan_tag = document.at(selector(:clan))
+ clan_tag.text if clan_tag
end
def model
div = document.at(selector(:model))
name = div['title']
@@ -25,16 +26,16 @@
Date.parse vitals.at(selector(:member)).next.text.match(/([\w.\s,]+)/)[1]
end
def last_game
node = vitals.at selector(:last)
- node ? decode_time(node['title']) : nil
+ decode_time(node['title']) if node
end
def time_played
node = vitals.at selector(:played)
- node ? GameTime.new(node['title']) : nil
+ GameTime.new(node['title']) if node
end
def wins
to_integer vitals.at(selector(:wins)).next.text
end
@@ -86,47 +87,47 @@
image = node.at('img.levelshot')['src']
Items::RecentGame.new(gametype, finish, played, image)
end.compact
- games.any? ? games : nil
+ games if games.any?
end
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').text
+ 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.any? ? competitors : nil
+ competitors if competitors.any?
end
private
def selectors
{
- :country => ".playername img",
- :nick => "#prf_player_name",
- :clan => ".playername a.clan",
- :model => ".prf_imagery div",
- :vitals => ".prf_vitals p",
- :member => "b:contains('Member Since')",
- :last => "b:contains('Last Game') + span",
- :played => "b:contains('Time Played') + span",
- :wins => "b:contains('Wins')",
- :losses => "b:contains('Losses')",
- :frags => "b:contains('Frags')",
- :hits => "b:contains('Hits')",
- :accuracy => "b:contains('Accuracy')",
- :favs => ".prf_faves b",
- :awards => ".prf_awards .awd_details",
- :games => ".recent_match",
- :competitors => "#qlv_profileBottomInset .rcmp_block"
+ country: "img.playerflag",
+ nick: ".profile_title",
+ clan: ".profile_title a.clan",
+ model: ".prf_imagery div",
+ vitals: ".prf_vitals p",
+ member: "b:contains('Member Since')",
+ last: "b:contains('Last Game') + span",
+ played: "b:contains('Time Played') + span",
+ wins: "b:contains('Wins')",
+ losses: "b:contains('Losses')",
+ frags: "b:contains('Frags')",
+ hits: "b:contains('Hits')",
+ accuracy: "b:contains('Accuracy')",
+ favs: ".prf_faves b",
+ awards: ".prf_awards .awd_details",
+ games: ".recent_match",
+ competitors: "#qlv_profileBottomInset .rcmp_block"
}
end
def decode_time(string)
Time.strptime(string, '%m/%d/%Y %H:%M %p')