Class: FootballNow::League
- Inherits:
-
Object
- Object
- FootballNow::League
- Defined in:
- lib/league.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#league_url ⇒ Object
Returns the value of attribute league_url.
-
#name ⇒ Object
Returns the value of attribute name.
-
#teams ⇒ Object
Returns the value of attribute teams.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_hash(league_hash) ⇒ Object
- .find_by_name(name) ⇒ Object
- .get_league_by_index(index) ⇒ Object
- .new_from_hash(league_hash) ⇒ Object
- .print_leagues ⇒ Object
- .reset ⇒ Object
Instance Method Summary collapse
- #add_team(team) ⇒ Object
- #current_round ⇒ Object
- #get_standings ⇒ Object
-
#initialize(name, league_url) ⇒ League
constructor
A new instance of League.
- #matches ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(name, league_url) ⇒ League
Returns a new instance of League.
7 8 9 10 11 |
# File 'lib/league.rb', line 7 def initialize(name, league_url) @name = name @league_url = league_url @teams = [] end |
Instance Attribute Details
#league_url ⇒ Object
Returns the value of attribute league_url.
3 4 5 |
# File 'lib/league.rb', line 3 def league_url @league_url end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/league.rb', line 3 def name @name end |
#teams ⇒ Object
Returns the value of attribute teams.
3 4 5 |
# File 'lib/league.rb', line 3 def teams @teams end |
Class Method Details
.all ⇒ Object
47 48 49 |
# File 'lib/league.rb', line 47 def self.all @@all end |
.create_from_hash(league_hash) ⇒ Object
43 44 45 |
# File 'lib/league.rb', line 43 def self.create_from_hash(league_hash) new_from_hash(league_hash).tap(&:save) end |
.find_by_name(name) ⇒ Object
35 36 37 |
# File 'lib/league.rb', line 35 def self.find_by_name(name) self.all.detect {|league| league.name.downcase == name.downcase} end |
.get_league_by_index(index) ⇒ Object
55 56 57 |
# File 'lib/league.rb', line 55 def self.get_league_by_index(index) self.all[index] end |
.new_from_hash(league_hash) ⇒ Object
39 40 41 |
# File 'lib/league.rb', line 39 def self.new_from_hash(league_hash) new(league_hash[:name], league_hash[:league_url]) end |
.print_leagues ⇒ Object
51 52 53 |
# File 'lib/league.rb', line 51 def self.print_leagues self.all.each.with_index(1) {|league, index| puts "#{index}. #{league.name}"} end |
.reset ⇒ Object
59 60 61 |
# File 'lib/league.rb', line 59 def self.reset @@all.clear end |
Instance Method Details
#add_team(team) ⇒ Object
18 19 20 21 |
# File 'lib/league.rb', line 18 def add_team(team) team.league ||= self @teams << team unless @teams.include? team end |
#current_round ⇒ Object
31 32 33 |
# File 'lib/league.rb', line 31 def current_round FootballNow::Match.most_recent_round_number(self) end |
#get_standings ⇒ Object
27 28 29 |
# File 'lib/league.rb', line 27 def get_standings @teams.sort {|a, b| a.standing.to_i <=> b.standing.to_i } end |
#matches ⇒ Object
23 24 25 |
# File 'lib/league.rb', line 23 def matches @teams.map { |team| team.matches }.flatten.uniq end |
#save ⇒ Object
13 14 15 16 |
# File 'lib/league.rb', line 13 def save @@all << self self end |