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

Coral Ruschak #15

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ replaced any attributes with `...` for readability.)
Notes: Contract length is in months, and the total cost is the contract length multiplied by the monthly cost.

```ruby
pry(main)> require './lib/player'
pry(main)> require git
#=> true

pry(main)> player = Player.new("Michael Palledorous" , 1000000, 36)
Expand Down
23 changes: 23 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Player
attr_reader :name, :monthly_cost, :contract_length

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

def first_name
name_array = @name.split
return name_array[0]
end

def last_name
name_array = @name.split
return name_array[1]
end

def total_cost
@monthly_cost * @contract_length
end
end
45 changes: 45 additions & 0 deletions lib/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class Team
attr_reader :name, :location, :roster

def initialize(name, location)
@name = name
@location = location
@roster = []
end

def player_count
@roster.count
end

def add_player(player)
@roster << player
end

def long_term_players
long_term = []
@roster.each do |player|
if player.contract_length > 24
long_term << player
end
end
return long_term
end

def short_term_players
short_term = []
@roster.each do |player|
if player.contract_length <= 24
short_term << player
end
end
return short_term
end

def total_value
payroll = 0
@roster.each do |player|
payroll += player.total_cost
end
return payroll
end
end
18 changes: 17 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,21 @@
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

describe '#nickname' do
it 'defaults to nil' do
player = Player.new("Michael Palledorous" , 1000000, 36)

expect(player.nickname).to eq(nil)
end

it 'sets & reads nickname'
player = Player.new("Michael Palledorous" , 1000000, 36)

player.set_nickname!("Squints")

expect(player.nickname).to eq("Squints")
end
end
105 changes: 105 additions & 0 deletions spec/team_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
require 'rspec'
require './lib/player'
require './lib/team'

RSpec.describe Team do
it 'exists' do
team = Team.new("Dodgers", "Los Angeles")

expect(team).to be_a Team
end

it 'has a name' do
team = Team.new("Dodgers", "Los Angeles")

expect(team.name).to eq("Dodgers")
end

it 'has a location' do
team = Team.new("Dodgers", "Los Angeles")

expect(team.location).to eq("Los Angeles")
end

describe '#roster'do
it 'defaults an empty array' do
team = Team.new("Dodgers", "Los Angeles")

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

it 'counts 0 as default' do
team = Team.new("Dodgers", "Los Angeles")

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

it 'can add_player' do
team = Team.new("Dodgers", "Los Angeles")
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])
end

it 'can accurately count with players in roster' do
team = Team.new("Dodgers", "Los Angeles")
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.player_count).to eq(2)
end
end

it 'creates array of long_term_players' do
team = Team.new("Dodgers", "Los Angeles")
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 'creates array of short_term_players' do
team = Team.new("Dodgers", "Los Angeles")
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 'accurately determines total cost of player contracts' do
team = Team.new("Dodgers", "Los Angeles")
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
end