Sha256: 4866e2ff443df584f1ad23a36cd51cdb44a165302aa6dba65d3818f1824a9e3e

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

module ScoreScraper
  module Scrapers
    class Mlb < Scraper

      private

      def formatted_url
        @formatted_url ||= "http://chicago.cubs.mlb.com/gdcross/components/game/mlb/year_#{search_year}/month_#{search_month}/day_#{search_day}/master_scoreboard.json"
      end

      def games
        @games ||= parsed_data['data']['games']['game']
      end

      def abbreviation(game, is_home = false)
        game["#{key_type(is_home)}_name_abbrev"]
      end

      def city(game, is_home = false)
        game["#{key_type(is_home)}_team_city"]
      end

      def game_state(game)
        game_state = ''
        game_status = game['status']['status']

        if game_status.downcase == 'final' || game_status.downcase == 'game over'
          game_state = 'F'
        elsif game_status.downcase == 'preview'
          game_state = game['time']
        elsif game['status']['top_inning'] && game['status']['inning']
          is_top_inning = game['status']['top_inning'].downcase == 'y'
          game_state = is_top_inning ? "T#{game['status']['inning']}" : "B#{game['status']['inning']}"
        end

        game_state
      end

      def nickname(game, is_home = false)
        game["#{key_type(is_home)}_team_name"]
      end

      def score(game, is_home = false)
        game['linescore'] ? game['linescore']['r']["#{key_type(is_home)}"] : ''
      end

      def key_type(is_home = false)
        is_home ? 'home' : 'away'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
score-scraper-0.1.4 lib/score_scraper/scrapers/mlb.rb
score-scraper-0.1.3 lib/score_scraper/scrapers/mlb.rb