Last active
September 17, 2015 05:05
-
-
Save jpotts18/5dfbeedec398cbf4f143 to your computer and use it in GitHub Desktop.
Explaining the Template Method design pattern with a WebScraper
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
class WebScraper | |
def execute | |
create_folders | |
download_data | |
parse_data | |
write_output | |
end | |
def create_folder | |
# Make directory | |
end | |
def download_data | |
# Initialize Http client | |
end | |
def parse_data | |
# Find all rows in table and put them in a hash | |
end | |
def write_output | |
# Write hash to a CSV on filesystem | |
end | |
end | |
class HTMLWebScraper < WebScraper | |
def parse_data | |
# customize how to extract the data into a hash and | |
# let the superclass take care of the rest :) | |
end | |
end | |
class JSONWebScraper < WebScraper | |
def download_data | |
# initialize JSON client | |
# save data to filesystem | |
end | |
def parse_data | |
# read from file system | |
# custom JSON parsing code | |
# store results in hash | |
# let the super class take care of the rest :) | |
end | |
end | |
html_scraper = HTMLWebScraper.new | |
html_scraper.execute | |
json_scraper = JSONWebScraper.new | |
json_scraper.excute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment