I want to be able to parse any url with ruby to get the main part of the domain without the www (just the XXXX.com)
Well you can write this method:
require 'URI'
def domain_name(url, arg={:with_dot_principal=>false})
arg[:with_dot_principal] ? URI(url).hostname.split('.').last(2).join('.') : URI(url).hostname.split('.').last(2).first
end
And using:
domain_name("https://www.google.com/?gws_rd=ssl&safe=active&ssui=on")
# => "google"
domain_name("http://google.com", with_dot_principal: true)
# => "google.com"