# Factory method returning an instance of
# the appropriate subclass.
+ # While we're looping through the list of subclasses,
+ # we'll set this to the Generic class.
+ generic = nil
+
# Check the URL against each website's class.
# The class will know whether or not the URL
# "belongs" to its website.
@subclasses.each do |w|
if w.owns_url?(url)
- return w.new(url)
+ if w.to_s == 'Generic'
+ generic = w
+ else
+ # We don't want to return Generic here because some
+ # other subclasses further down the list might match
+ # the URL.
+ return w.new(url)
+ end
end
end
- # If nothing matched, we don't return an instance
- # of anything.
- return nil
+ # If nothing matched, try the generic parser.
+ return generic.new(url)
end