class QuakeliveApi::Parser::Statistics
Public Instance Methods
records()
click to toggle source
# File lib/quakelive_api/parser/statistics.rb, line 23 def records return if no_records? document.css(selector(:record)).map do |node| next if no_records? attrs = { title: node.at('.col_st_gametype').text.strip, played: to_integer(node.at('.col_st_played').text), finished: to_integer(node.at('.col_st_finished').text), wins: to_integer(node.at('.col_st_wins').text), quits: to_integer(node.at('.col_st_withdraws').text), completed: to_integer(node.at('.col_st_completeperc').text.gsub('%','')), wins_percentage: to_integer(node.at('.col_st_winperc').text.gsub('%','')) } Items::Record.new(attrs) end end
weapons()
click to toggle source
# File lib/quakelive_api/parser/statistics.rb, line 5 def weapons document.css(selector(:weapon)).each_with_index.map do |node, idx| next if node.children.empty? # messed-up html by id, thanks attrs = { name: next_element(:name, idx).content, frags: frags(next_element(:frags, idx)), accuracy: accuracy(next_element(:accuracy, idx)), usage: usage(next_element(:usage, idx)) } hits, shots = hits_shots(next_element(:accuracy, idx)) attrs.merge!(hits: hits, shots: shots) Items::Weapon.new(attrs) end end
Private Instance Methods
accuracy(node)
click to toggle source
# File lib/quakelive_api/parser/statistics.rb, line 87 def accuracy(node) return if node.text =~ /^n\/a$/i to_integer node.at('span').text.gsub("%","") end
frags(node)
click to toggle source
# File lib/quakelive_api/parser/statistics.rb, line 83 def frags(node) to_integer node.text end
hits_shots(node)
click to toggle source
71,259 / 247,016 (28.85%)
# File lib/quakelive_api/parser/statistics.rb, line 61 def hits_shots(node) return [nil, nil] unless node['title'] selector = if node['title'] =~ /hits/i /Hits: ([\d,]+) Shots: ([\d,]+)/i else /([\d,]+)\s+\/\s+([\d,]+)/i end res = node['title'].match(selector) [res[1], res[2]].map { |r| to_integer r } end
next_element(css, index)
click to toggle source
# File lib/quakelive_api/parser/statistics.rb, line 79 def next_element(css, index) document.css(".prf_weapons #{selector(css)}")[index] end
no_records?()
click to toggle source
# File lib/quakelive_api/parser/statistics.rb, line 56 def no_records? document.at(selector(:record)).nil? end
selectors()
click to toggle source
# File lib/quakelive_api/parser/statistics.rb, line 45 def selectors { weapon: ".prf_weapons p", name: ".col_weapon", frags: ".col_frags", accuracy: ".col_accuracy", usage: ".col_usage", record: ".qlv_profile_section_statistics .prf_record > div" } end
usage(node)
click to toggle source
# File lib/quakelive_api/parser/statistics.rb, line 75 def usage(node) to_integer node.text.gsub(/%|,/, '') end