Sha256: b37b717497a41df2b3b82a3d63cbce087613b0809d44ba10bd6919dbfcc4bbe9

Contents?: true

Size: 1.28 KB

Versions: 24

Compression:

Stored size: 1.28 KB

Contents

module Sportradar
  module Api
    class Nfl::Drive < Data
      attr_accessor :response, :id, :sequence, :start_reason, :end_reason, :play_count, :duration, :first_downs, :gain, :penalty_yards, :scoring_drive, :quarter, :team, :plays

      def initialize(data)
        @response = data
        @id = data["id"]
        @sequence = data["sequence"]
        @start_reason = data["start_reason"]
        @end_reason = data["end_reason"]
        @play_count = data["play_count"]
        @duration = data["duration"]
        @first_downs = data["first_downs"]
        @gain = data["gain"]
        @penalty_yards = data["penalty_yards"]
        @scoring_drive = data["scoring_drive"]
        @quarter = Sportradar::Api::Nfl::Quarter.new data["quarter"] if data["quarter"]
        @team = Sportradar::Api::Nfl::Team.new data["team"] if data["team"]
        set_plays

      end

      private

      def set_plays
        if response["plays"] && response["plays"]["play"]
          if response["plays"]["play"].is_a?(Array)
            @plays = response["plays"]["play"].map {|play| Sportradar::Api::Nfl::Play.new play }
          elsif response["plays"]["play"].is_a?(Hash)
            @plays = [ Sportradar::Api::Nfl::Play.new(response["plays"]["play"]) ]
          end
        end
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
sportradar-api-0.1.8 lib/sportradar/api/nfl/drive.rb
sportradar-api-0.1.7 lib/sportradar/api/nfl/drive.rb
sportradar-api-0.1.6 lib/sportradar/api/nfl/drive.rb
sportradar-api-0.1.5 lib/sportradar/api/nfl/drive.rb