Class: Footballdata::Stat
- Inherits:
-
Object
- Object
- Footballdata::Stat
- Defined in:
- lib/footballdata/stat.rb
Overview
rename to match stat or something why? why not?
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize ⇒ Stat
constructor
A new instance of Stat.
- #update(match) ⇒ Object
Constructor Details
#initialize ⇒ Stat
Returns a new instance of Stat.
4 5 6 |
# File 'lib/footballdata/stat.rb', line 4 def initialize @data = {} end |
Instance Method Details
#[](key) ⇒ Object
8 |
# File 'lib/footballdata/stat.rb', line 8 def [](key) @data[ key ]; end |
#update(match) ⇒ Object
10 11 12 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 51 52 53 54 |
# File 'lib/footballdata/stat.rb', line 10 def update( match ) ## keep track of some statistics stat = @data[:all] ||= { stage: Hash.new( 0 ), duration: Hash.new( 0 ), status: Hash.new( 0 ), group: Hash.new( 0 ), matchday: Hash.new( 0 ), matches: 0, goals: 0, } stat[:stage][ match['stage'] ] += 1 stat[:group][ match['group'] ] += 1 stat[:status][ match['status'] ] += 1 stat[:matchday][ match['matchday'] ] += 1 score = match['score'] stat[:duration][ score['duration'] ] += 1 ## track - assert always REGULAR stat[:matches] += 1 stat[:goals] += score['fullTime']['homeTeam'].to_i if score['fullTime']['homeTeam'] stat[:goals] += score['fullTime']['awayTeam'].to_i if score['fullTime']['awayTeam'] stage_key = match['stage'].downcase.to_sym # e.g. :regular_season stat = @data[ stage_key ] ||= { duration: Hash.new( 0 ), status: Hash.new( 0 ), group: Hash.new( 0 ), matchday: Hash.new( 0 ), matches: 0, goals: 0, } stat[:group][ match['group'] ] += 1 stat[:status][ match['status'] ] += 1 stat[:matchday][ match['matchday'] ] += 1 stat[:duration][ score['duration'] ] += 1 ## track - assert always REGULAR stat[:matches] += 1 stat[:goals] += score['fullTime']['homeTeam'].to_i if score['fullTime']['homeTeam'] stat[:goals] += score['fullTime']['awayTeam'].to_i if score['fullTime']['awayTeam'] end |