Class: OvercastAPI::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/overcast_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container) ⇒ Player

Returns a new instance of Player.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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

Instance Attribute Details

#bioObject (readonly)

Returns the value of attribute bio.



41
42
43
# File 'lib/overcast_api.rb', line 41

def bio
  @bio
end

Returns the value of attribute contact_links.



39
40
41
# File 'lib/overcast_api.rb', line 39

def contact_links
  @contact_links
end

#contactsObject (readonly)

Returns the value of attribute contacts.



38
39
40
# File 'lib/overcast_api.rb', line 38

def contacts
  @contacts
end

#days_playedObject (readonly)

Returns the value of attribute days_played.



35
36
37
# File 'lib/overcast_api.rb', line 35

def days_played
  @days_played
end

#deathsObject (readonly)

Returns the value of attribute deaths.



30
31
32
# File 'lib/overcast_api.rb', line 30

def deaths
  @deaths
end

#friend_countObject (readonly)

Returns the value of attribute friend_count.



31
32
33
# File 'lib/overcast_api.rb', line 31

def friend_count
  @friend_count
end

#infoObject (readonly)

Returns the value of attribute info.



40
41
42
# File 'lib/overcast_api.rb', line 40

def info
  @info
end

#infractionsObject (readonly)

Returns the value of attribute infractions.



44
45
46
# File 'lib/overcast_api.rb', line 44

def infractions
  @infractions
end

#kd_rationObject (readonly)

Returns the value of attribute kd_ration.



32
33
34
# File 'lib/overcast_api.rb', line 32

def kd_ration
  @kd_ration
end

#killsObject (readonly)

Returns the value of attribute kills.



29
30
31
# File 'lib/overcast_api.rb', line 29

def kills
  @kills
end

#kk_ratioObject (readonly)

Returns the value of attribute kk_ratio.



33
34
35
# File 'lib/overcast_api.rb', line 33

def kk_ratio
  @kk_ratio
end

#monumentsObject (readonly)

Returns the value of attribute monuments.



37
38
39
# File 'lib/overcast_api.rb', line 37

def monuments
  @monuments
end

#name_colorObject (readonly)

Returns the value of attribute name_color.



28
29
30
# File 'lib/overcast_api.rb', line 28

def name_color
  @name_color
end

#pvp_encountersObject (readonly)

Returns the value of attribute pvp_encounters.



43
44
45
# File 'lib/overcast_api.rb', line 43

def pvp_encounters
  @pvp_encounters
end

#raindropsObject (readonly)

Returns the value of attribute raindrops.



36
37
38
# File 'lib/overcast_api.rb', line 36

def raindrops
  @raindrops
end

#ranksObject (readonly)

Returns the value of attribute ranks.



27
28
29
# File 'lib/overcast_api.rb', line 27

def ranks
  @ranks
end

#server_joinsObject (readonly)

Returns the value of attribute server_joins.



34
35
36
# File 'lib/overcast_api.rb', line 34

def server_joins
  @server_joins
end

#statusObject (readonly)

Returns the value of attribute status.



26
27
28
# File 'lib/overcast_api.rb', line 26

def status
  @status
end

#trophiesObject (readonly)

Returns the value of attribute trophies.



42
43
44
# File 'lib/overcast_api.rb', line 42

def trophies
  @trophies
end

#usernameObject (readonly)

Returns the value of attribute username.



25
26
27
# File 'lib/overcast_api.rb', line 25

def username
  @username
end