Class: FootballNow::Team
- Inherits:
-
Object
- Object
- FootballNow::Team
- Defined in:
- lib/team.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#draws ⇒ Object
Returns the value of attribute draws.
-
#goals_against ⇒ Object
Returns the value of attribute goals_against.
-
#goals_for ⇒ Object
Returns the value of attribute goals_for.
-
#league ⇒ Object
Returns the value of attribute league.
-
#losses ⇒ Object
Returns the value of attribute losses.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#name ⇒ Object
Returns the value of attribute name.
-
#points ⇒ Object
Returns the value of attribute points.
-
#standing ⇒ Object
Returns the value of attribute standing.
-
#wins ⇒ Object
Returns the value of attribute wins.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_hash(team_data) ⇒ Object
- .find_by_name(team_name) ⇒ Object
- .reset ⇒ Object
Instance Method Summary collapse
- #add_match(match, key) ⇒ Object
-
#initialize(name, opt = {}) ⇒ Team
constructor
A new instance of Team.
- #save ⇒ Object
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
#draws ⇒ Object
Returns the value of attribute draws.
3 4 5 |
# File 'lib/team.rb', line 3 def draws @draws end |
#goals_against ⇒ Object
Returns the value of attribute goals_against.
3 4 5 |
# File 'lib/team.rb', line 3 def goals_against @goals_against end |
#goals_for ⇒ Object
Returns the value of attribute goals_for.
3 4 5 |
# File 'lib/team.rb', line 3 def goals_for @goals_for end |
#league ⇒ Object
Returns the value of attribute league.
3 4 5 |
# File 'lib/team.rb', line 3 def league @league end |
#losses ⇒ Object
Returns the value of attribute losses.
3 4 5 |
# File 'lib/team.rb', line 3 def losses @losses end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
5 6 7 |
# File 'lib/team.rb', line 5 def matches @matches end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/team.rb', line 3 def name @name end |
#points ⇒ Object
Returns the value of attribute points.
3 4 5 |
# File 'lib/team.rb', line 3 def points @points end |
#standing ⇒ Object
Returns the value of attribute standing.
3 4 5 |
# File 'lib/team.rb', line 3 def standing @standing end |
#wins ⇒ Object
Returns the value of attribute wins.
3 4 5 |
# File 'lib/team.rb', line 3 def wins @wins end |
Class Method Details
.all ⇒ Object
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 |
.reset ⇒ Object
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 |
#save ⇒ Object
15 16 17 18 |
# File 'lib/team.rb', line 15 def save @@all << self self end |