Skip to content

Instantly share code, notes, and snippets.

@r1ckhenry
Created October 15, 2015 14:28
Show Gist options
  • Save r1ckhenry/f4a722323d0750b5832a to your computer and use it in GitHub Desktop.
Save r1ckhenry/f4a722323d0750b5832a to your computer and use it in GitHub Desktop.
FaceClan
# 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