class MyLameWebsiteScraper def fetch_data_from_location puts "First I fetch the data" record = Object.new write_to_csv record end def write_to_csv(record) puts "Then I write it to a csv file. Here's a bunch of logic that does that" puts "Okay I'm writing it #{record}\n\n" end end #l = MyLameWebsiteScraper.new #l.fetch_data_from_location class MyEvenLamerScraper def fetch_data_from_location puts "First I fetch some other data in some other way" record = Object.new write_to_csv record end def write_to_csv(record) puts "Then I write it to a csv file. Here's a bunch of logic that does that" puts "Okay I'm writing it #{record}\n\n" end end #l = MyEvenLamerScraper.new #l.fetch_data_from_location class LameAbstractScraper #Scraper def fetch_data_from_location puts "Hopefully I'm getting overridden. By default I do nothing." end def write_to_csv(record) # Base implementation to be shared puts "Then I write it to a csv file. Here's a bunch of logic that does that" puts "Okay I'm writing it #{record}\n\n" end end class MyLameWebsiteScraperExt < LameAbstractScraper #OSUScraper def fetch_data_from_location puts "First I fetch the data" record = Object.new write_to_csv record end end #ml = MyLameWebsiteScraperExt.new #ml.fetch_data_from_location class MyLameWebsiteScraperExt < LameAbstractScraper #CSCCScraper def fetch_data_from_location puts "First I fetch the data for cscc" record = Object.new write_to_csv record end end class MyNumberCalculator < LameAbstractScraper # huh? def do_work puts "I'm calculating a series of numbers and writing them to a csv file" x = [1,2,3,4,5,6] write_to_csv x end end ur = MyNumberCalculator.new ur.do_work ur.fetch_data_from_location # what the heck is this even supposed to do? ######################## module DataStorage def write_to_csv(record) puts "I'm writing to a csv file" puts "I'll put in the csv file whatever I'm passed" puts "in this case it is #{record}" recordToWrite = record.get_record_array recordToWrite.each File.new (filename).write do |val| end end end def load_from_csv puts "here's a loaded record from the csv file" return DataRecord.new end class WritableDataRecord def get_record_array # This method should be overriden and return an array of strings # In the order you want them in the file end end end class OsuWebsiteScraper include DataStorage def fetch_data_from_location #get the data and populate a record someData = "whatever data should be" write_to_csv someData end end class OtherWebsiteScraper include DataStorage def fetch_data_from_location someOtherData = WritableDataRecord.new write_to_csv someOtherData end end class MyOtherNumberCalculator include DataStorage def do_work x = [1,2,3,4,5] write_to_csv x end end ###### class WebsiteScraper include DataStorage def fetch_data_from_location (&fetchLogic) someCustomData = yield # any other common logic write_to_csv someCustomData end end #myFirstScraper = OsuWebsiteScraper.new #myFirstScraper.fetch_data_from_location #myFirstScraper = OtherWebsiteScraper.new #myFirstScraper.fetch_data_from_location # #MyOtherNumberCalculator.new.do_work flexibleScraper = WebsiteScraper.new flexibleScraper.fetch_data_from_location do puts "I can put whatever logic I want here. Let's return a string that's the data we want to write." "Here's my data to write" end