class OvercastAPI::Player

Attributes

bio[R]
contacts[R]
days_played[R]
deaths[R]
friend_count[R]
info[R]
infractions[R]
kd_ration[R]
kills[R]
kk_ratio[R]
monuments[R]
name_color[R]
pvp_encounters[R]
raindrops[R]
ranks[R]
server_joins[R]
status[R]
trophies[R]
username[R]

Public Class Methods

new(container) click to toggle source
# File lib/overcast_api.rb, line 46
def initialize(container)
  header = container.xpath "section/div[@class='page-header']"
  @username = header.xpath('h1/span').text
  @username.gsub! "\n", ''
  @status = header.xpath('h1/small').text
  @status.gsub! "\n", ''

  row = container.xpath "section/div[@class='row']"

  @ranks = []
  ranks_container = row.xpath "div[@class='span7']/div[@class='row-fluid']/div[@class='span8']/div[@class='row-fluid']/div[@class='span7']/div/span"
  ranks_container.each do |rank_node|
    name = rank_node.text
    color = rank_node['style'].gsub(' ', '').split(';')[0].split(':')[1]
    @ranks << Rank.new(name, color)
  end

  @kills = row.xpath("div[@class='span7']/div[@class='row-fluid']/div[@class='span8']/div[@class='row-fluid']/div[@class='span5']/h2").text
  @kills = @kills.gsub!("\n", '').to_i

  @deaths = row.xpath("div[@class='span7']/div[@class='row-fluid']/div[@class='span4']/h2").text
  @deaths = @deaths.gsub!("\n", '').to_i

  #puts row.xpath("div[@class='span2']/h2")
  @friend_count = row.xpath("div[@class='span2']/h2")[0].text
  @friend_count = @friend_count.gsub!("\n", '').to_i

  stats_list = row.xpath("div[@class='span3']/h2")

  @kd_ratio = stats_list[0].text.gsub!("\n", '').to_f
  @kk_ratio = stats_list[1].text.gsub!("\n", '').to_f
  @server_joins = stats_list[2].text.gsub!("\n", '').to_i
  @days_played = stats_list[3].text.gsub!("\n", '').to_f
  @raindrops = stats_list[4].text.gsub!("\n", '')
  k = @raindrops.include? 'k'
  @raindrops = @raindrops.to_f
  @raindrops *= 1000 if k
  @raindrops = @raindrops.to_i

  info_tabs = container.xpath "section[2]/div[@class='row']/div[@class='span12']/div[@class='tabbable']/div[@class='tab-content']"

  about = info_tabs.xpath "div[@id='about']"
  contacts = about.xpath "div[1][@class='row']/div[@class='span4']"
  @contacts = {}
  @contact_links = {}
  contacts.each do |contact|
    key = contact.xpath("h6").text
    if key == 'Team'
      value = contact.xpath("blockquote/a").text
      link = BASE_URL + contact.xpath("blockquote/a")[0]['href']
    else
      value = contact.xpath("blockquote/p/a").text
      link = contact.xpath("blockquote/p/a")[0]['href']
    end
    @contacts[key] = value
    @contact_links[key] = link
  end

  description = about.xpath "div[2][@class='row']/div[@class='span6']"
  @info = {}
  description.each do |info|
    key = info.xpath("h6").text
    value = info.xpath("pre").text
    @info[key] = value
  end

  @bio = about.xpath("div[3][@class='row']/div[@class='span12']/pre").text

  trophy_case = info_tabs.xpath "div[@id='trophycase']/div/div/ul/li"
  @trophies = []
  trophy_case.each do |trophy|
    div = trophy.xpath('div')[0]
    description = div['title']
    name = div.xpath('h4').text
    icon = div.xpath('div/i')[0]['class']
    trophies << Trophy.new(name, description, icon)
  end

  pvp_encounters = info_tabs.xpath "div[@id='pvp-encounters']/div/div[@class='span6']"
  @pvp_encounters = []
  pvp_encounters.each do |col|
    col.xpath('p').each do |encounter|
      parts = encounter.xpath('a')
      killer = parts[0].children[0]['title']
      victim = parts[1].children[0]['title']
      map = parts[2].text
      time = parts[3]['title']
      @pvp_encounters << PvPEncounter.new(killer, victim, map, time)
    end
  end

  infractions_table = info_tabs.xpath "div[@id='infractions']/div/div/table/tbody/tr"
  @infractions = []
  infractions_table.each do |inf|
    slots = inf.children # <td>
    # @infractions << Infraction.new(punisher, punished, reason, type, expires, date)
  end

end