Class: CSstats::Player
- Inherits:
-
Object
- Object
- CSstats::Player
- Defined in:
- lib/csstats/player.rb
Instance Attribute Summary collapse
-
#rank ⇒ Object
Returns the value of attribute rank.
Instance Method Summary collapse
- #accuracy ⇒ Object
- #as_json ⇒ Object
- #efficiency ⇒ Object
-
#initialize(attributes = {}) ⇒ Player
constructor
A new instance of Player.
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
#rank ⇒ Object
Returns the value of attribute rank.
5 6 7 |
# File 'lib/csstats/player.rb', line 5 def rank @rank end |
Instance Method Details
#accuracy ⇒ Object
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_json ⇒ Object
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 |
#efficiency ⇒ Object
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 |