class YankeeScore::Game
Constants
- END_GAME_STATE
- PRE_GAME_STATE
Attributes
away_team[RW]
home_team[RW]
inning[RW]
inning_state[RW]
score[RW]
start_time[RW]
status[RW]
Public Class Methods
all()
click to toggle source
# File lib/yankee_score/game.rb, line 20 def self.all @@all end
create_from_json(game_hash)
click to toggle source
# File lib/yankee_score/game.rb, line 32 def self.create_from_json(game_hash) game = self.new(YankeeScore::Team.new(game_hash[:home_name_abbrev]), YankeeScore::Team.new(game_hash[:away_name_abbrev])) game.start_time = game_hash[:time] game.status = game_hash[:status][:status] game.inning = game_hash[:status][:inning] game.inning_state = game_hash[:status][:inning_state] if game_hash.has_key?(:linescore) game.home_team.runs = game_hash[:linescore][:r][:home] game.away_team.runs = game_hash[:linescore][:r][:away] game.score = "#{game.away_team.runs}-#{game.home_team.runs}" end game.save end
find_team_by_abbrev(team_abbrev)
click to toggle source
# File lib/yankee_score/game.rb, line 51 def self.find_team_by_abbrev(team_abbrev) self.all.select do |team| team_abbrev == team.home_team.name || team_abbrev == team.away_team.name end end
new(home_team, away_team)
click to toggle source
# File lib/yankee_score/game.rb, line 13 def initialize(home_team, away_team) @home_team = home_team @away_team = away_team end
reset_all!()
click to toggle source
# File lib/yankee_score/game.rb, line 24 def self.reset_all! @@all.clear end
Public Instance Methods
is_active?()
click to toggle source
# File lib/yankee_score/game.rb, line 61 def is_active? self.inning.to_i >= 1 && !is_over? && !PRE_GAME_STATE.include?(status) end
is_over?()
click to toggle source
# File lib/yankee_score/game.rb, line 57 def is_over? END_GAME_STATE.include?(self.status) end
save()
click to toggle source
# File lib/yankee_score/game.rb, line 28 def save @@all << self end