Class: FifaRankings::Team

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(team_hash) ⇒ Team

Returns a new instance of Team.



7
8
9
10
11
12
# File 'lib/fifa_rankings/team.rb', line 7

def initialize(team_hash)
  team_hash.each do |k,v|
    self.send(("#{k}="),v)
  end
  @@all << self
end

Instance Attribute Details

#captainObject

Returns the value of attribute captain.



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

def captain
  @captain
end

#confederationObject

Returns the value of attribute confederation.



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

def confederation
  @confederation
end

#head_coachObject

Returns the value of attribute head_coach.



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

def head_coach
  @head_coach
end

#most_capsObject

Returns the value of attribute most_caps.



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

def most_caps
  @most_caps
end

#movementObject

Returns the value of attribute movement.



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

def movement
  @movement
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#pointsObject

Returns the value of attribute points.



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

def points
  @points
end

#rankObject

Returns the value of attribute rank.



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

def rank
  @rank
end

#top_scorerObject

Returns the value of attribute top_scorer.



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

def top_scorer
  @top_scorer
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



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

def self.all
  @@all
end

.create_from_array(array) ⇒ Object



18
19
20
21
# File 'lib/fifa_rankings/team.rb', line 18

def self.create_from_array(array)
  # create Team instances from an array of hashes
  array.each {|team| self.new(team)}
end

.find_by_name(name) ⇒ Object



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

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

.find_by_rank(rank) ⇒ Object



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

def self.find_by_rank(rank)
  self.all.detect {|team| team.rank == rank}
end

.points_greater_than(number) ⇒ Object



14
15
16
# File 'lib/fifa_rankings/team.rb', line 14

def self.points_greater_than(number)
  self.all.select {|team| team.points > number}
end

.sort_by_rankObject



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

def self.sort_by_rank
  self.all.sort_by {|team| team.rank}
end

Instance Method Details

#add_attributes(attributes_hash) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/fifa_rankings/team.rb', line 23

def add_attributes(attributes_hash)
  # add attributes to Team instances from a hash for the detail view
  attributes_hash.each do |k,v|
    self.send(("#{k}="),v)
  end
  self
end