Created
October 15, 2015 14:28
-
-
Save r1ckhenry/f4a722323d0750b5832a to your computer and use it in GitHub Desktop.
FaceClan
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
# main.rb | |
require 'pry-byebug' | |
require 'pg' | |
def db | |
@db ||= PG.connect(dbname: 'faceclan', host: 'localhost') | |
end | |
def menu | |
# Clear the screen, and present the user with a menu | |
puts `clear` | |
puts "*** TheFaceClan (we're thinking of changing the name) ***" | |
puts "While we sell your private information to advertisers, choose an option:" | |
print "(l)ist friends, (a)dd friend, (u)n-friend or (q)uit: " | |
gets.chomp.downcase | |
end | |
def unknown_action | |
puts "Sorry, I don't know what to do with that" | |
end | |
def pause | |
puts "press enter to continue" | |
gets | |
end | |
def list_friends | |
db.exec( "SELECT * FROM friends" ) do |result| | |
result.each do |row| | |
binding.pry; '' | |
# need to do stuff here | |
end | |
end | |
end | |
begin | |
response = menu | |
until response == 'q' | |
case response | |
when 'l' | |
list_friends | |
else | |
unknown_action | |
end | |
pause | |
response = menu | |
end | |
ensure | |
db.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment