Class: FootballNow::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/match.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ Match

Returns a new instance of Match.



8
9
10
# File 'lib/match.rb', line 8

def initialize(opt = {})
  opt.each {|method, arg| send("#{method}=", arg) if respond_to?("#{method}=") }
end

Instance Attribute Details

#away_scoreObject

Returns the value of attribute away_score.



3
4
5
# File 'lib/match.rb', line 3

def away_score
  @away_score
end

#away_teamObject

Returns the value of attribute away_team.



4
5
6
# File 'lib/match.rb', line 4

def away_team
  @away_team
end

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/match.rb', line 3

def date
  @date
end

#home_scoreObject

Returns the value of attribute home_score.



3
4
5
# File 'lib/match.rb', line 3

def home_score
  @home_score
end

#home_teamObject

Returns the value of attribute home_team.



4
5
6
# File 'lib/match.rb', line 4

def home_team
  @home_team
end

#roundObject

Returns the value of attribute round.



3
4
5
# File 'lib/match.rb', line 3

def round
  @round
end

Class Method Details

.allObject



35
36
37
# File 'lib/match.rb', line 35

def self.all
  @@all
end

.create_from_hash(match_hash) ⇒ Object



26
27
28
# File 'lib/match.rb', line 26

def self.create_from_hash(match_hash)
  new(match_hash).tap(&:save)
end

.get_recent_results(league) ⇒ Object



39
40
41
42
# File 'lib/match.rb', line 39

def self.get_recent_results(league)
  round_number = most_recent_round_number(league)
  league.matches.select {|match| match.round == round_number}
end

.most_recent_round_number(league) ⇒ Object



44
45
46
# File 'lib/match.rb', line 44

def self.most_recent_round_number(league)
  league.matches.max {|a,b| a.round <=> b.round}.round
end

Instance Method Details

#leagueObject



22
23
24
# File 'lib/match.rb', line 22

def league
  @home_team.league
end

#saveObject



30
31
32
33
# File 'lib/match.rb', line 30

def save
  @@all << self
  self
end