Sha256: dec287d0ed013dfaafa51cf654bb57368622d22fe585fdfa0b4cb655776c7481

Contents?: true

Size: 1.75 KB

Versions: 50

Compression:

Stored size: 1.75 KB

Contents

module Sportradar
  module Api
    module Soccer
      class Scoring < Data
        attr_accessor :response, :api, :id, :home, :away, :scores

        def initialize(data, **opts)
          @api      = opts[:api]
          @match    = opts[:match]
          
          @scores = {}
          @id = data['id']
          
          update(data, **opts)
        end

        def update(data, source: nil, **opts)
          # new_scores = case source
          # when :box
          #   parse_from_box(data)
          # when :timeline
          #   parse_from_timeline(data)
          # when :summary
          #   parse_from_box(data)
          # else
          #   if data['period'] || data['half']
          #     parse_from_timeline(data)
          #   elsif data['team']
          #     parse_from_box(data)
          #   else # schedule requests
          #     {}
          #   end
          # end
          new_scores = parse_from_timeline(data)
          # parse data structure
          # handle data from team (all periods)
          # handle data from period (both teams)
          # handle data from match?
          @scores.each { |k, v| v.merge!(new_scores.delete(k) || {} ) }
          new_scores.each { |k, v| @scores.merge!(k => v) }
        end

        def goals(team_id)
          @score[team_id].to_i
        end


        private

        def parse_from_timeline(data)
          if data['period_scores']
            data['period_scores'].map do |hash|
              [hash["number"], {"home"=>hash['home_score'], "away"=>hash['away_score']}]
            end.to_h
          else
            {}
          end
        end

        # def period_name
        #   'period'
        # end

        def parse_from_summary(data)
          # 
        end

      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
sportradar-api-0.20.2 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.20.1 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.20.0 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.20.0.pre2 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.20.0.pre lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.19.6 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.19.5 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.19.4 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.19.3 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.19.2 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.19.1 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.19.0 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.18.1 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.18.0 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.17.6 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.17.5 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.17.5.pre lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.17.4 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.17.3 lib/sportradar/api/soccer/scoring.rb
sportradar-api-0.17.2 lib/sportradar/api/soccer/scoring.rb