Sha256: 4390eb589c939fca6347ad083ec73381319a0e208a6be03bb9b26c15eec48a72

Contents?: true

Size: 513 Bytes

Versions: 11

Compression:

Stored size: 513 Bytes

Contents

module SportsDataApi
  module Mlb
    class Scoring
      attr_reader :scoring

      def initialize(scoring)
        @scoring = scoring
      end

      def inning
        @inning ||= last_inning ? last_inning['number'] : nil
      end

      def inning_half
        return unless last_inning

        @inning_half ||= last_inning['runs'] == 'X' ? 'top' : 'bot'
      end

      private

      def last_inning
        @last_inning ||= (scoring || []).sort_by { |i| i['number'] }.last
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sports_data_api-0.15.3 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.15.2 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.15.1 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.15.0 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.14.1 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.14.0 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.13.0 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.12.1 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.12.0 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.11.6 lib/sports_data_api/mlb/scoring.rb
sports_data_api-0.11.5 lib/sports_data_api/mlb/scoring.rb