Skip to content
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
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'https://rubygems.org'
ruby '2.0.0'
ruby '2.2.1'

gem 'rspec', '~> 3.0.0.beta2'
gem 'rspec'
gem 'pry'
14 changes: 13 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.2)
diff-lcs (1.2.5)
method_source (0.9.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
Expand All @@ -19,4 +24,11 @@ PLATFORMS
ruby

DEPENDENCIES
rspec (~> 3.0.0.beta2)
pry
rspec

RUBY VERSION
ruby 2.2.1p85

BUNDLED WITH
1.16.1
49 changes: 38 additions & 11 deletions lib/deaf_grandma.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,67 @@
#This script is different than FizzBuzz. It should accept user input from the terminal if done correctly. Run it to see what it does then complete the speak method so that it returns & prints the correct thing.
#This script is different than FizzBuzz. It should accept user input from the terminal if done correctly.
#Run it to see what it does then complete the speak method so that it returns & prints the correct thing.

#CAREFUL! This script will not exit. Do you know why? You may have to close it with `Ctrl-C` (Mac) if you do not insert an `exit` into your speak method.
#CAREFUL! This script will not exit. Do you know why? You may have to close it with `Ctrl-C` (Mac)
#if you do not insert an `exit` into your speak method.

class DeafGrandma
attr_accessor :bye_counter

def initialize
@bye_counter = 0
@bye_counter = 0
end

def run!
print_welcome

loop do
user_input = get_user_input
p speak(user_input)
end
user_input = get_user_input
process_user_input(user_input)
end
end

def process_user_input(input)
if input == "BYE"
@bye_counter += 1
if @bye_counter == 3
abort("SEE YOU LATER SONNY!")
end
else
speak(input)
end
end

def speak(input)
@input = input
if speak_softly?
"SPEAK UP SONNY!"
elsif yell?
"NOT SINCE 1964!"
end
end

#Implement your code here <<<<<<<<<
private

def get_user_input
print "> "
gets.chomp.gsub(/\s+/, "")
end

private
def input_scanner
@input.scan(/[A-Z]/).length
end

def print_welcome
puts "\nSpeak to your Grandmother: "
end

def get_user_input
print "> "
gets.chomp
def speak_softly?
input_scanner == 0
end

def yell?
input_scanner == @input.length
end
end

#Uncomment this next line to run your script but BE SURE to comment it, before you try and run your tests.
Expand Down
12 changes: 9 additions & 3 deletions lib/fizzbuzz.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
class SuperFizzBuzz

def run(input)

#Implement your code here

if (input % 3 == 0) and (input % 5 == 0)
"FizzBuzz"
elsif (input % 3 == 0)
"Fizz"
elsif (input % 5 == 0)
"Buzz"
else
input
end
end

end
Expand Down
12 changes: 7 additions & 5 deletions spec/deaf_grandma_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
require 'rspec'
require 'deaf_grandma'
require 'pry'

describe 'DeafGrandma' do
let(:script) { DeafGrandma.new }

it "says 'SPEAK UP SONNY!' when we speak regularly" do
expect(script.speak("Hi Grandma")).to eq "SPEAK UP SONNY!"
expect(script.speak("speak")).to eq "SPEAK UP SONNY!"
end

it "says 'NOT SINCE 1964!' when we yell" do
#implement your test here
expect(script.speak("YELL")).to eq "NOT SINCE 1964!"
end

it "EXTRA CREDIT: How would you test yelling BYE?" do
#implement your test here
it "says 'SEE YOU LATER SONNY!' when we say 'BYE' 3 times" do
script.bye_counter = 2
expect(script.process_user_input("BYE")).to eq "SEE YOU LATER SONNY!"
end
end
15 changes: 8 additions & 7 deletions spec/fizzbuzz_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
describe 'SuperFizzBuzz' do
let(:script) { SuperFizzBuzz.new }

it "returns 'Fizz' when my input is divisible by 3" do
expect(script.run(3)).to eq "Fizz"
end

it "returns 'Fizz' when my input is divisible by 3" do
expect(script.run(3)).to eq "Fizz"
end

it "returns 'Buzz' when my input is divisible by 5" do
#implement your test here
expect(script.run(5)).to eq "Buzz"
end

it "returns 'FizzBuzz' when input is divisible by 3 & 5" do
#implement your test here
end

it "returns the input number when input isn't divisible by 3, 5, or both" do
#implement your test here
expect(script.run(15)).to eq "FizzBuzz"
end

end