Pokemon Scraper

Learning Goals

  • Set up a SQLite database
  • Scrape and save data into your database
  • Use data to make ruby objects

Introduction

In this lab, you will set up your schema, scrape data, insert it into your db and then build out methods to manipulate your data.

For our purposes the Pokemon class is responsible for saving, adding, removing, or changing anything about each Pokémon. Your scraper is not responsible for knowing anything about them.

Note

We have set up your scraper class for you, which you can see in lib/scraper.rb. We have also created a schema_migration.sql file that will run the SQL statement to set up your database in db/pokemon.db. Your only job is to build out the methods to save and find pokemon in the database.

Create Our Pokemon Class

Our Pokemon class can be found in lib/pokemon.rb. This is where you will build your methods. Notice that #initialize requires keyword arguments.

A Note On Inserting Into the Database

When you use SQL to insert into a database you write out the values by hand and insert them into the database. However, when you insert your Pokémon into the database you don't want to insert them into the query via string interpolation because of potential dangerous consequences. Instead, we can do two things:

It is generally recommended to go with parameters. Check out this Stack Overflow question for a good example.