Good work! Per your desire to sharpen your MVC skills, here are some detailed notes on your code:
-
You have a
puts
call in yourDisplay
class'sinitialize
method. Instead, you are going to want yourController
to utilize yourDisplay.look_at_this
method 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 assignment
in yourDisplay
class. This should be in yourController
. So in yourController
you 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
Controller
code in itsinitialize
method, and some code outside of itsinitialize
method. Better to just have one method that controls the program flow, and call that method in yourController
initialize
method. So yourController
would 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 thePage
model, so that all you would have in yourController
would 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_s
method on yourPage
class. Even better: you realize that, when callingputs
on an object with ato_s
method, that Ruby will automatically call theto_s
method on that object. (You realize you do not need to explicitly callto_s
.) -
You don't need this
send
method. Just call yourDisplay
methods directly on your@viewer
instance variable.
Any questions, let me know.
-Phil