Class: FootballNow::Match
- Inherits:
-
Object
- Object
- FootballNow::Match
- Defined in:
- lib/match.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#away_score ⇒ Object
Returns the value of attribute away_score.
-
#away_team ⇒ Object
Returns the value of attribute away_team.
-
#date ⇒ Object
Returns the value of attribute date.
-
#home_score ⇒ Object
Returns the value of attribute home_score.
-
#home_team ⇒ Object
Returns the value of attribute home_team.
-
#round ⇒ Object
Returns the value of attribute round.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_hash(match_hash) ⇒ Object
- .get_recent_results(league) ⇒ Object
- .most_recent_round_number(league) ⇒ Object
Instance Method Summary collapse
-
#initialize(opt = {}) ⇒ Match
constructor
A new instance of Match.
- #league ⇒ Object
- #save ⇒ Object
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_score ⇒ Object
Returns the value of attribute away_score.
3 4 5 |
# File 'lib/match.rb', line 3 def away_score @away_score end |
#away_team ⇒ Object
Returns the value of attribute away_team.
4 5 6 |
# File 'lib/match.rb', line 4 def away_team @away_team end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/match.rb', line 3 def date @date end |
#home_score ⇒ Object
Returns the value of attribute home_score.
3 4 5 |
# File 'lib/match.rb', line 3 def home_score @home_score end |
#home_team ⇒ Object
Returns the value of attribute home_team.
4 5 6 |
# File 'lib/match.rb', line 4 def home_team @home_team end |
#round ⇒ Object
Returns the value of attribute round.
3 4 5 |
# File 'lib/match.rb', line 3 def round @round end |
Class Method Details
.all ⇒ Object
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
#league ⇒ Object
22 23 24 |
# File 'lib/match.rb', line 22 def league @home_team.league end |
#save ⇒ Object
30 31 32 33 |
# File 'lib/match.rb', line 30 def save @@all << self self end |