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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/quakelive_api/parser/statistics.rb', line 21

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
# File 'lib/quakelive_api/parser/statistics.rb', line 5

def weapons
  document.css(selector(:weapon)).each_with_index.map do |node, idx|
    attrs = {
      :name     => node.text,
      :frags    => frags(weapon_next(:frags, idx)),
      :accuracy => accuracy(weapon_next(:accuracy, idx)),
      :usage    => usage(weapon_next(:usage, idx))
    }

    hits, shots = hits_shots(weapon_next(:accuracy, idx))
    attrs.merge!(:hits => hits, :shots => shots)

    Items::Weapon.new(attrs)
  end
end