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.
5 6 7 8 9 10 11 12 13 |
# File 'lib/csstats/player.rb', line 5 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.
3 4 5 |
# File 'lib/csstats/player.rb', line 3 def rank @rank end |
Instance Method Details
#accuracy ⇒ Object
22 23 24 25 26 |
# File 'lib/csstats/player.rb', line 22 def accuracy return 0.0 if shots.to_f.zero? (hits.to_f / shots.to_f * 100).round(2) end |
#as_json ⇒ Object
28 29 30 31 32 |
# File 'lib/csstats/player.rb', line 28 def as_json CSstats::COLUMN_KEYS.each_with_object({}) do |column, object| object[column] = send(column) end end |
#efficiency ⇒ Object
15 16 17 18 19 20 |
# File 'lib/csstats/player.rb', line 15 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 |