Good work! Per your desire to sharpen your MVC skills, here are some detailed notes on your code:
-
You have a
putscall in yourDisplayclass'sinitializemethod. Instead, you are going to want yourControllerto utilize yourDisplay.look_at_thismethod to print this initial welcome text to the console:@viewer.look_at_this("Welcome to the World's Simplest Browser")
Or, you could write a specific Display method for this:
#Display class code:
def welcome
puts "Welcome to the World's Simplest Browser"
end
#Controller code:
@viewer.welcome-
You have a
gets.chomp assignmentin yourDisplayclass. This should be in yourController. So in yourControlleryou would have something like this:@viewer.look_at_this("What website would you like to visit today?") # or @viewer.site_prompt with only the 'puts' in the site_prompt method site = gets.chomp
-
You have some of your
Controllercode in itsinitializemethod, and some code outside of itsinitializemethod. Better to just have one method that controls the program flow, and call that method in yourControllerinitializemethod. So yourControllerwould end up looking like this:class Controller def initialize self.run end def run #controller code goes here end end
-
You've got a lot of parsing happening in your
Controller. This should be happening in your classes or modules. Specifically for this, it would be better to have a module that parses the data and delivers it to thePagemodel, so that all you would have in yourControllerwould be the calls to these methods, like this:# ParsingModule would receive the URL and return a hash # from which Page.new could create a Page object. # So all of the parsing happens in the module @page = Page.new(ParsingModule.parse(@url)) @viewer.look_at_this(@page)
-
Nice work having a
to_smethod on yourPageclass. Even better: you realize that, when callingputson an object with ato_smethod, that Ruby will automatically call theto_smethod on that object. (You realize you do not need to explicitly callto_s.) -
You don't need this
sendmethod. Just call yourDisplaymethods directly on your@viewerinstance variable.
Any questions, let me know.
-Phil