Sha256: da6de5e8c6b6e165c7a4a2fcb35427161e1bdf3f1c949b0ce7ab3cadd4c00821

Contents?: true

Size: 795 Bytes

Versions: 3

Compression:

Stored size: 795 Bytes

Contents

module ScoreScraper 
	class Scoreboard

		def initialize(search_date = nil, teams = [])
			@teams = teams
			@search_date = search_date || Time.now.strftime("%Y-%m-%d") 
		end

		def games(game_separator = '|')
			game_array = []

			team_games.each do |game|
				game_array << single_game(game)
			end

			game_array.join(game_separator)
		end

		private

		attr_reader :search_date, :teams
	
		def parser
			raise 'must be implemented by child class'
		end

		def single_game(game)
			home_team = game.home_team
			away_team = game.away_team

			" #{away_team.abbreviation} #{away_team.score} - #{home_team.score} #{home_team.abbreviation} #{game.game_state} "
		end

		def team_games
			return @team_games unless @team_games.nil?

			@team_games = parser.games_for_teams || {}
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
score-scraper-0.1.2 lib/score_scraper/scoreboard.rb
score-scraper-0.1.1 lib/score_scraper/scoreboard.rb
score-scraper-0.1.0 lib/score_scraper/scoreboard.rb