Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jacob Inman - IC1 - sports_ball_2412 #4

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
46 changes: 46 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class Player
attr_reader :name, :monthly_cost, :contract_length, :nickname

def initialize(name, monthly_cost, contract_length)
@name = name
@monthly_cost = monthly_cost
@contract_length = contract_length
@nickname = ()
end

def first_name

name.split.first

end

def last_name

name.split.last

end

def monthly_cost

@monthly_cost

end

def contract_length

@contract_length

end

def total_cost

@monthly_cost * @contract_length

end

def set_nickname(nickname)

@nickname = nickname

end
end
95 changes: 95 additions & 0 deletions lib/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
class Team
attr_reader :team_name, :city, :roster

def initialize(team_name, city)
@team_name = team_name
@city = city
@roster = []
end

def roster

@roster

end

def player_count

@roster.length

end

def add_player(player)

@roster << player

end

def long_term_players

long_term_players = []

roster.find_all do |player|
if player.contract_length > 24
long_term_players << player
end
end

long_term_players

end

def short_term_players

short_term_players = []

roster.find_all do |player|
if player.contract_length <= 24
short_term_players << player
end
end

short_term_players

end

def total_value

cost_array = []

roster.each do |player|
cost_array << player.total_cost
end

cost_array.sum

end

def details

details = {}
details["total_value"] = total_value
details["player_count"] = player_count

details
end

def average_cost_of_player

average_cost = "$" + ((total_value / player_count).to_s).gsub(/\B(?=(...)*\b)/, ',')

end

def players_by_last_name

surname = []

@roster.each do |player|
surname << player.last_name
end

surname.sort! * ", "

end

end
14 changes: 13 additions & 1 deletion spec/player_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rspec'
require './lib/player'

RSpec.describe Player do
it 'exists' do
Expand Down Expand Up @@ -34,6 +35,17 @@
it 'has a total cost' do
player = Player.new("Michael Palledorous" , 1000000, 36)

expect(player.total_costg).to eq(36000000)
expect(player.total_cost).to eq(36000000)
end

it 'can give a player a nickname' do
player = Player.new("Michael Palledorous" , 1000000, 36)

expect(player.nickname).to eq nil

player.set_nickname("Squints")

expect(player.nickname).to eq("Squints")
end

end
132 changes: 132 additions & 0 deletions spec/team_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
require 'rspec'
require './lib/player'
require './lib/team'

RSpec.describe Team do
it 'exists' do
team = Team.new("Padres", "San Diego")

expect(team).to be_a Team
end

it 'has roster space' do
team = Team.new("Padres", "San Diego")

expect(team.roster).to eq([])
end

it 'can count players' do
team = Team.new("Padres", "San Diego")

expect(team.player_count).to eq(0)
end

it 'players can be added' do
team = Team.new("Padres", "San Diego")

player_1 = Player.new("Michael Palledorous", 1000000, 36)
player_2 = Player.new("Kenny DeNunez", 500000, 24)

team.add_player(player_1)
team.add_player(player_2)

expect(team.roster).to eq([player_1, player_2])
expect(team.player_count).to eq(2)
end

it 'can determine long term players' do
team = Team.new("Padres", "San Diego")

player_1 = Player.new("Michael Palledorous", 1000000, 36)
player_2 = Player.new("Kenny DeNunez", 500000, 24)
player_3 = Player.new("Alan McClennan", 750000, 48)
player_4 = Player.new("Hamilton Porter", 100000, 12)

team.add_player(player_1)
team.add_player(player_2)
team.add_player(player_3)
team.add_player(player_4)

expect(team.long_term_players).to eq([player_1, player_3])
end

it 'can determine short term players' do
team = Team.new("Padres", "San Diego")

player_1 = Player.new("Michael Palledorous", 1000000, 36)
player_2 = Player.new("Kenny DeNunez", 500000, 24)
player_3 = Player.new("Alan McClennan", 750000, 48)
player_4 = Player.new("Hamilton Porter", 100000, 12)

team.add_player(player_1)
team.add_player(player_2)
team.add_player(player_3)
team.add_player(player_4)

expect(team.short_term_players).to eq([player_2, player_4])
end

it 'can total the teams complete cost value' do
team = Team.new("Padres", "San Diego")

player_1 = Player.new("Michael Palledorous", 1000000, 36)
player_2 = Player.new("Kenny DeNunez", 500000, 24)
player_3 = Player.new("Alan McClennan", 750000, 48)
player_4 = Player.new("Hamilton Porter", 100000, 12)

team.add_player(player_1)
team.add_player(player_2)
team.add_player(player_3)
team.add_player(player_4)

expect(team.total_value).to eq(85200000)
end

it 'can collect the team details' do
team = Team.new("Padres", "San Diego")

player_1 = Player.new("Michael Palledorous", 1000000, 36)
player_2 = Player.new("Kenny DeNunez", 500000, 24)
player_3 = Player.new("Alan McClennan", 750000, 48)
player_4 = Player.new("Hamilton Porter", 100000, 12)

team.add_player(player_1)
team.add_player(player_2)
team.add_player(player_3)
team.add_player(player_4)

expect(team.details).to eq({"total_value" => 85200000, "player_count" => 4})
end

it 'can tell the average cost of players' do
team = Team.new("Padres", "San Diego")

player_1 = Player.new("Michael Palledorous", 1000000, 36)
player_2 = Player.new("Kenny DeNunez", 500000, 24)
player_3 = Player.new("Alan McClennan", 750000, 48)
player_4 = Player.new("Hamilton Porter", 100000, 12)

team.add_player(player_1)
team.add_player(player_2)
team.add_player(player_3)
team.add_player(player_4)

expect(team.average_cost_of_player).to eq("$21,300,000")
end

it 'can alphabetize roster by last name' do
team = Team.new("Padres", "San Diego")

player_1 = Player.new("Michael Palledorous", 1000000, 36)
player_2 = Player.new("Kenny DeNunez", 500000, 24)
player_3 = Player.new("Alan McClennan", 750000, 48)
player_4 = Player.new("Hamilton Porter", 100000, 12)

team.add_player(player_1)
team.add_player(player_2)
team.add_player(player_3)
team.add_player(player_4)

expect(team.players_by_last_name).to eq("DeNunez, McClennan, Palledorous, Porter")
end
end