Class: MatcheshHistory
- Inherits:
-
Object
- Object
- MatcheshHistory
- Defined in:
- lib/api/utils/matches_history.rb
Overview
This class is used to get the data from the match history
Instance Attribute Summary collapse
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
Instance Method Summary collapse
- #accuracy(name, tag) ⇒ Object
-
#initialize(hash) ⇒ MatcheshHistory
constructor
A new instance of MatcheshHistory.
- #most_played(name, tag) ⇒ Object
Constructor Details
#initialize(hash) ⇒ MatcheshHistory
Returns a new instance of MatcheshHistory.
9 10 11 |
# File 'lib/api/utils/matches_history.rb', line 9 def initialize(hash) @matches = fetch_matches(hash['data']) end |
Instance Attribute Details
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
7 8 9 |
# File 'lib/api/utils/matches_history.rb', line 7 def matches @matches end |
Instance Method Details
#accuracy(name, tag) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/api/utils/matches_history.rb', line 13 def accuracy(name, tag) body_shots = 0 head_shots = 0 leg_shots = 0 @matches.each do |match| headshots, bodyshots, legshots = match.accuracy(name, tag) head_shots += headshots body_shots += bodyshots leg_shots += legshots end [head_shots, body_shots, leg_shots] end |
#most_played(name, tag) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/api/utils/matches_history.rb', line 29 def most_played(name, tag) most_played = [] @matches.each do |match| match.all_players.each do |player| next unless player.name.gsub(' ', '') == name.gsub(' ', '') && player.tag == tag most_played << player.character end end most_played.max_by { |i| most_played.count(i) } end |