Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Extract the registered domain name from a URI.
Add this line to your application's Gemfile:
gem 'domainator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install domainator
There are two approaches to parsing domains with Domainator: Domainator.parse
and Domainator#parse
.
Call the Domainator.parse
method with a URI object or parseable URI string.
Domainator.parse('http://www.google.com')
# => "google.com"
uri = URI.parse('http://maps.google.co.uk/map?foo=bar')
Domainator.parse(uri)
# => "google.co.uk"
Domainator.parse('http://10.0.0.1')
# => Domainator::NotFoundError: no matching domain for "http://10.0.0.1"
A second parameter can alternatively be passed to define the known extensions.
This parameter should be an Enumerable
(optimally a Set
) in which each
extension contains the leading dot. By default, this value is set to
Domainator.default_extensions
.
extensions = %w[.com .net .co.uk].to_set
Domainator.parse('http://www.google.com', extensions)
# => "google.com"
Domainator.parse('http://www.google.ca', extensions)
# => Domainator::NotFoundError: no matching domain for "http://www.google.ca"
If a domain is found, then a string will be returned. Otherwise, one of the following errors will be raised:
ArgumentError
: the URI param was not passed in as a String
or URI
, or
the URI param does not include a host, or the extensions param was not passed
in as an Enumerable
.URI::InvalidURIError
: the URI was passed in as a String
and cannot be
parsed.Domainator::NotFoundError
: the URI does not contain a valid domain name.Instantiate a Domainator
object by passing in an optional set of valid domain
extensions. By default, this value is set to Domainator.default_extensions
.
domainator = Domainator.new
# => #<Domainator:0x007fda8428a8f0 @extensions=#<Set: {".ac", ".com.ac", ".gov.ac", ".mil.ac", ... }>>
domainator = Domainator.new(%w[.com .net].to_set)
# => #<Domainator:0x007fda823861c0 @extensions=#<Set: {".com", ".net"}>>
Once instantiated, call the #parse
method with a URI object or parseable URI
string.
domainator.parse('http://www.google.com')
# => "google.com"
domainator.parse('http://www.google.foo')
# => Domainator::NotFoundError: no matching domain for "http://www.google.foo"
To see the list of domain extensions built into the gem, call the
Domainator.default_extensions
method.
Domainator.default_extensions
# => #<Set: {".ac", ".com.ac", ".gov.ac", ".mil.ac", ... }>
You can manually add to and remove from this list via the
Set#add
(Set#<<
)
and Set#delete
methods.
Domainator.default_extensions.include? '.foo'
# => false
Domainator.default_extensions.include? '.com'
# => true
Domainator.default_extensions << '.foo'
Domainator.default_extensions.delete('.com')
Domainator.default_extensions.include? '.foo'
# => true
Domainator.default_extensions.include? '.com'
# => false
This gem does not currently work with domains that require right-to-left language support.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that domainator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.