-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51a08d2
commit a617718
Showing
7 changed files
with
203 additions
and
45 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def students | ||
@students ||= [] | ||
end | ||
|
||
def add(student) | ||
students << student | ||
end | ||
|
||
def student_to_s(student) | ||
"#{student[:name]}, #{student[:cohort]} cohort" | ||
end | ||
|
||
def students_to_s | ||
students.map.with_index(1) do |student, index| | ||
"#{index}.#{student_to_s(student)}" | ||
end.join("\n") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
def add(student) | ||
students << student | ||
end | ||
|
||
def students | ||
@students ||= [] | ||
end | ||
|
||
def student_to_s(student) | ||
"#{student[:name]}, #{student[:cohort]} cohort" | ||
end | ||
|
||
def students_to_s | ||
students.map.with_index(1) do |student, index| | ||
"#{index}. #{student_to_s(student)}" | ||
end.join("\n") | ||
end | ||
|
||
def print_students | ||
show students_to_s | ||
end | ||
|
||
# def is_a_hash? | ||
# true | ||
# end | ||
|
||
# def user_input | ||
# gets.chomp | ||
# end | ||
|
||
def show(string) | ||
puts string | ||
end | ||
|
||
def print_header | ||
show "Welcome to the Makers Academy\nThe students of my cohort are..." | ||
end | ||
|
||
def print_footer(names) | ||
show "Overall , we have #{names.length} superdooper students" | ||
end | ||
|
||
def print_array | ||
show "test" | ||
end | ||
|
||
def request_name | ||
show "Please enter the student's name" | ||
request("name") | ||
end | ||
|
||
def request_cohort | ||
show "Please enter the student's cohort" | ||
request("cohort") | ||
end | ||
|
||
def request_hobby | ||
show "Please enter the student's hobby" | ||
request("hobby") | ||
end | ||
|
||
def request(thing) | ||
thing = gets.chomp | ||
end | ||
|
||
|
||
|
||
# request(hobby) | ||
# request(cohort) | ||
# request() | ||
|
||
# request_hobby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'directory5' | ||
|
||
describe 'student directory' do | ||
it 'has no students' do | ||
expect(students).to be_empty | ||
end | ||
|
||
it 'add a student' do | ||
student = [{name: "David", cohort: "June"}] | ||
add(student) | ||
expect(students).to eq [student] | ||
end | ||
|
||
it 'give us a student line' do | ||
student = {name: "David", cohort: "June"} | ||
expect(student_to_s(student)).to eq "David, June cohort" | ||
end | ||
|
||
it 'gives us a whole bunch of student lines' do | ||
["David", "chloe", "sam"].each do |name| | ||
add({name: name, cohort: "June"}) | ||
end | ||
expect(students_to_s).to eq "1.David, June cohort\n2.chloe, June cohort\n3.sam, June cohort" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
require 'directory5' | ||
|
||
describe 'student directory' do | ||
it 'has no students' do | ||
expect(students).to be_empty | ||
end | ||
|
||
it 'adds a student' do | ||
student = { name: "David", cohort: "June" } | ||
add(student) | ||
expect(students).to eq [student] | ||
end | ||
|
||
it 'gives us a student line' do | ||
student = { name: "David", cohort: "June" } | ||
expect(student_to_s(student)).to eq 'David, June cohort' | ||
end | ||
|
||
it 'gives us a whole bunch of student lines' do | ||
%w{David Chloe Zoe}.each do |name| | ||
add({name: name, cohort: 'June'}) | ||
end | ||
|
||
expect(students_to_s).to eq "1. David, June cohort\n2. Chloe, June cohort\n3. Zoe, June cohort" | ||
end | ||
|
||
it 'prints em' do | ||
%w{David Chloe Zoe}.each do |name| | ||
add({name: name, cohort: 'June'}) | ||
end | ||
expect(self).to receive(:show).with("1. David, June cohort\n2. Chloe, June cohort\n3. Zoe, June cohort") | ||
|
||
print_students | ||
end | ||
|
||
context 'informs about schtuff' do | ||
|
||
it 'prints a string to the terminal' do | ||
expect(self).to receive(:puts).with("HELLO!") | ||
show("HELLO!") | ||
end | ||
|
||
it 'prints header' do | ||
expect(self).to receive(:show).with("Welcome to the Makers Academy\nThe students of my cohort are...") | ||
print_header | ||
end | ||
|
||
it 'prints footer' do | ||
expect(self).to receive(:show) | ||
print_footer(students) | ||
end | ||
end | ||
|
||
context 'should prompt for' do | ||
it 'name' do | ||
input = "Chloe" | ||
expect(self).to receive(:puts).with("Please enter the student's name") | ||
expect(self).to receive(:gets).and_return(input) | ||
expect(request_name).to eq "Chloe" | ||
end | ||
|
||
it 'cohort' do | ||
input = "June" | ||
expect(self).to receive(:puts).with("Please enter the student's cohort") | ||
expect(self).to receive(:gets).and_return(input) | ||
expect(request_cohort).to eq "June" | ||
end | ||
|
||
it 'hobby' do | ||
input = "Being noisy" | ||
expect(self).to receive(:puts).with("Please enter the student's hobby") | ||
expect(self).to receive(:gets).and_return(input) | ||
expect(request_hobby).to eq "Being noisy" | ||
end | ||
|
||
# it 'anything we want' do | ||
# thing = hobby | ||
# expect(self).to receive(:puts).with("Please enter the student's #{thing}") | ||
# expect(self).to receive(:gets).and_return(thing) | ||
# expect(request(thing)).to eq "hobby" | ||
# end | ||
|
||
end | ||
|
||
# it 'prints each of the elements in a hash' do | ||
# expect(self).to receive(:show) | ||
# print_array | ||
# end | ||
end |