Class: QuakeliveApi::Parser::Statistics

Inherits:
Base
  • Object
show all
Defined in:
lib/quakelive_api/parser/statistics.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #invalid_player?, #request_error?

Constructor Details

This class inherits a constructor from QuakeliveApi::Parser::Base

Instance Method Details

#recordsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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

#weaponsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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