Class: FootballNow::Team

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opt = {}) ⇒ Team

Returns a new instance of Team.



9
10
11
12
13
# File 'lib/team.rb', line 9

def initialize(name, opt={})
  @name = name
  @matches = []
  opt.each {|method, arg| send("#{method}=", arg) if self.respond_to?("#{method}=")}
end

Instance Attribute Details

#drawsObject

Returns the value of attribute draws.



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

def draws
  @draws
end

#goals_againstObject

Returns the value of attribute goals_against.



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

def goals_against
  @goals_against
end

#goals_forObject

Returns the value of attribute goals_for.



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

def goals_for
  @goals_for
end

#leagueObject

Returns the value of attribute league.



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

def league
  @league
end

#lossesObject

Returns the value of attribute losses.



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

def losses
  @losses
end

#matchesObject (readonly)

Returns the value of attribute matches.



5
6
7
# File 'lib/team.rb', line 5

def matches
  @matches
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#pointsObject

Returns the value of attribute points.



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

def points
  @points
end

#standingObject

Returns the value of attribute standing.



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

def standing
  @standing
end

#winsObject

Returns the value of attribute wins.



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

def wins
  @wins
end

Class Method Details

.allObject



38
39
40
# File 'lib/team.rb', line 38

def self.all
  @@all
end

.create_from_hash(team_data) ⇒ Object



34
35
36
# File 'lib/team.rb', line 34

def self.create_from_hash(team_data)
  team = new(team_data[:name], team_data).tap(&:save)
end

.find_by_name(team_name) ⇒ Object



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

def self.find_by_name(team_name)
  @@all.detect {|team| team.name.downcase == team_name.downcase}
end

.resetObject



42
43
44
# File 'lib/team.rb', line 42

def self.reset
  @@all.clear
end

Instance Method Details

#add_match(match, key) ⇒ Object



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

def add_match(match, key)
  match.send("#{key}=", self) unless match.send(key)
  @matches << match
end

#saveObject



15
16
17
18
# File 'lib/team.rb', line 15

def save
  @@all << self
  self
end