Skip to content

Instantly share code, notes, and snippets.

@iheartkode
Last active August 29, 2015 14:03
Show Gist options
  • Save iheartkode/5edbc79db9fdc263cf80 to your computer and use it in GitHub Desktop.
Save iheartkode/5edbc79db9fdc263cf80 to your computer and use it in GitHub Desktop.
require 'sqlite3'
#Open the SQLite3 Database
@db = SQLite3::Database.open "data.db"
#Getting information to create a bot with
def start
puts "Enter a Bots name:"
@name = gets.chomp
puts "Enter the age:"
@age = gets.chomp
puts "Enter a job:"
@job = gets.chomp
end
#Inserting data in to data.db
def insert
{
"name:" => @name,
"age:" => @age,
"job:" => @job
}.each do |pair|
@db.execute "insert into bots values ( ?, ?,? )", pair
end
end
#Showing inserted bots data and asks to show all bots.
def view
puts "Your bot has been added..."
puts "The name is #{@name} and the age is #{@age} and the job is #{@job}"
sleep 3
puts "Would you like to list all the bots?"
answer = gets.chomp.downcase
#Asking if they want to see all the bots.
if answer == "yes"
@db.execute( "select * from bots" ) do |row|
puts row
end
else
puts "Goodbye!"
end
#Close the connection
@db.close()
end
start
insert
view
require 'sqlite3'
# Code to open the SQlite database.
@db = SQLite3::Database.open "data.db"
# Method used to start the information gathering.
def start
puts "Enter a Bots name:"
@name = gets.chomp
puts "Enter the age:"
@age = gets.chomp
puts "Enter a job:"
@job = gets.chomp
end
# Method used to insert the data into SQlite.
def insert
{
"name:" => @name,
"age:" => @age,
"job:" => @job
}.each do |pair|
@db.execute "insert into bots values ( ?, ?,? )", pair
end
end
# Method used to put info on the created bot and asks to show all bots.
def view
puts "Your bot has been added..."
puts "The name is #{@name} and the age is #{@age} and the job is #{@job}"
sleep 3
puts "Would you like to list all the bots?"
answer = gets.chomp.downcase
if answer == "yes"
@db.execute( "select * from bots" ) do |row|
puts row
end
else
puts "Goodbye!"
end
# Close the SQlite data connection.
@db.close()
end
# Start the sections of the program.
start
insert
view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment