Class: CSstats::Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Player

Returns a new instance of Player.



7
8
9
10
11
12
13
14
15
# File 'lib/csstats/player.rb', line 7

def initialize(attributes = {})
  CSstats::COLUMN_KEYS.each do |column|
    self.class.send(:attr_accessor, column)
  end

  attributes.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#rankObject

Returns the value of attribute rank.



5
6
7
# File 'lib/csstats/player.rb', line 5

def rank
  @rank
end

Instance Method Details

#accuracyObject



24
25
26
27
28
# File 'lib/csstats/player.rb', line 24

def accuracy
  return 0.0 if shots.to_f.zero?

  (hits.to_f / shots.to_f * 100).round(2)
end

#as_jsonObject



30
31
32
33
34
# File 'lib/csstats/player.rb', line 30

def as_json
  CSstats::COLUMN_KEYS.each_with_object({}) do |column, object|
    object[column] = send(column)
  end
end

#efficiencyObject



17
18
19
20
21
22
# File 'lib/csstats/player.rb', line 17

def efficiency
  kills_and_deaths = kills.to_f + deaths.to_f
  return 0.0 if kills_and_deaths.zero?

  (kills.to_f / kills_and_deaths * 100).round(2)
end