Class: Gorgerb::PlayerStatistics
- Inherits:
-
Object
- Object
- Gorgerb::PlayerStatistics
- Defined in:
- lib/gorgerb/player_statistics.rb
Defined Under Namespace
Classes: Accuracy, KDR, MarineAccuracy, Meta, StatisticsPoint
Instance Attribute Summary collapse
-
#steam_id ⇒ Object
readonly
Returns the value of attribute steam_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(steam_id, statistics_points) ⇒ PlayerStatistics
constructor
A new instance of PlayerStatistics.
- #method_missing(m, *args, &block) ⇒ Object
Constructor Details
#initialize(steam_id, statistics_points) ⇒ PlayerStatistics
Returns a new instance of PlayerStatistics.
52 53 54 55 |
# File 'lib/gorgerb/player_statistics.rb', line 52 def initialize(steam_id, statistics_points) @steam_id = steam_id @statistics_points = statistics_points end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/gorgerb/player_statistics.rb', line 57 def method_missing(m, *args, &block) stats_class = m.to_s if @statistics_points.key? stats_class @statistics_points[stats_class] else super(m, *args, &block) end end |
Instance Attribute Details
#steam_id ⇒ Object (readonly)
Returns the value of attribute steam_id.
11 12 13 |
# File 'lib/gorgerb/player_statistics.rb', line 11 def steam_id @steam_id end |
Class Method Details
.from_hsh(data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gorgerb/player_statistics.rb', line 13 def self.from_hsh(data) stats_points = {} steam_id = data.fetch('_').fetch('steam_id') # Prevent it being treated as a stats point further below. data.delete('_') data.each do |stats_class, class_data| kdr_data = class_data.fetch('kdr') accuracy_data = class_data.fetch('accuracy') = class_data.fetch('_') kdr = KDR.new( kdr_data.fetch('alien'), kdr_data.fetch('marine') ) accuracy = Accuracy.new( accuracy_data.fetch('alien'), MarineAccuracy.new( accuracy_data.fetch('marine').fetch('total'), accuracy_data.fetch('marine').fetch('no_onos'), ) ) = Meta.new( .fetch('sample_size') ) stats_points[stats_class] = StatisticsPoint.new( , kdr, accuracy ) end PlayerStatistics.new(steam_id, stats_points) end |