Class: FootballNow::League

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_urlObject

Returns the value of attribute league_url.



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

def league_url
  @league_url
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#teamsObject

Returns the value of attribute teams.



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

def teams
  @teams
end

Class Method Details

.allObject



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


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

.resetObject



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_roundObject



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

def current_round
  FootballNow::Match.most_recent_round_number(self)
end

#get_standingsObject



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

#matchesObject



23
24
25
# File 'lib/league.rb', line 23

def matches
  @teams.map { |team| team.matches }.flatten.uniq
end

#saveObject



13
14
15
16
# File 'lib/league.rb', line 13

def save
  @@all << self
  self
end