Created
November 25, 2013 02:43
-
-
Save vanmichael/7635460 to your computer and use it in GitHub Desktop.
Phase 4
This file contains hidden or 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
| #Echo Phase 4 | |
| class Echo | |
| def initialize | |
| @comments = [] | |
| get_input | |
| if @input == "Nothing!" | |
| puts "Ok, fine!" | |
| elsif @input == "I have a lot to say" | |
| respond_to_something_prepared | |
| read_file | |
| print_comments | |
| else | |
| play_back(@input) | |
| end | |
| end | |
| def get_input | |
| puts "What do you want to say?" | |
| @input = gets.chomp | |
| end | |
| def play_back(response) | |
| puts "You said: #{response}" | |
| end | |
| def respond_to_alot | |
| puts "Ok, Let's hear it!" | |
| comments = [] | |
| while @input != "done" | |
| @input = gets.chomp | |
| comments << @input if @input != "done" | |
| end | |
| print_comments | |
| end | |
| def respond_to_something_prepared | |
| puts "Ok, where can I find what you want to say?" | |
| @file = gets.chomp | |
| respond_to_something_prepared if validate_file_type? != true | |
| end | |
| def print_comments | |
| @comments.each do |comment| | |
| puts "You said: #{comment}" if comment == @comments.first | |
| puts "Then, you said: #{comment}" if comment != @comments.first && comment != @comments.last | |
| puts "Finally, you said: #{comment}" if comment == @comments.last | |
| end | |
| puts "Phew! Glad you got all #{@comments.length} of those things off your chest!" | |
| end | |
| def read_file | |
| puts "Loading speech.txt..." | |
| File.open(@file, 'r').each_line do |comment| | |
| @comments << comment | |
| end | |
| end | |
| def validate_file_type? | |
| puts "invalid try again!" | |
| @format = @file.split('.') | |
| if @format[1] == "txt" | |
| return true | |
| end | |
| end | |
| end | |
| Echo.new |
This file contains hidden or 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
| We're leaving ground | |
| Will things ever be the same again? | |
| It's the final countdown | |
| The final countdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment