-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from benbalter/iso
ISO Country Code support
- Loading branch information
Showing
7 changed files
with
167 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,29 +22,33 @@ Or add this to your `Gemfile` before doing a `bundle install`: | |
|
||
## Usage | ||
|
||
### In general | ||
|
||
### Verify email addresses | ||
|
||
```ruby | ||
Gman.valid? "[email protected]" #true | ||
Gman.valid? "[email protected]" #false | ||
Gman.valid? "[email protected]" #=> true | ||
Gman.valid? "[email protected]" #=> false | ||
``` | ||
|
||
### Verify domain | ||
|
||
```ruby | ||
Gman.valid? "http://foo.bar.gov" #true | ||
Gman.valid? "foo.bar.gov" #true | ||
Gman.valid? "foo.gov" #true | ||
Gman.valid? "foo.biz" #false | ||
Gman.valid? "http://foo.bar.gov" #=> true | ||
Gman.valid? "foo.bar.gov" #=> true | ||
Gman.valid? "foo.gov" #=> true | ||
Gman.valid? "foo.biz" #=> false | ||
``` | ||
|
||
### Get a domain name from an arbitrary domain string | ||
### Get the ISO Country Code information represented by a government domain | ||
|
||
```ruby | ||
Gman.get_domain "http://foo.bar.gov" # foo.bar.gov | ||
Gman.get_domain "[email protected]" # bar.gov | ||
Gman.get_domain "foo.bar.gov" # foo.bar.gov | ||
Gman.get_domain "asdf@asdf" # nil (no domain within the string) | ||
domain = Gman.new "whitehouse.gov" #=> #<Gman domain="whitehouse.gov" valid=true> | ||
domain.country.name #=> "United States" | ||
domain.country.alpha2 #=> "US" | ||
domain.country.alpha3 #=> "USA" | ||
domain.country.currency #=> "USD" | ||
domain.conutry.calling_code #=> "+1" | ||
``` | ||
|
||
## Contributing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Gman | ||
VERSION = '2.1.3' | ||
class Gman | ||
VERSION = '3.0.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,37 +44,51 @@ class TestGman < Minitest::Test | |
end | ||
|
||
should "properly parse domains from strings" do | ||
assert_equal "github.gov", Gman::get_domain("[email protected]") | ||
assert_equal "foo.github.gov", Gman::get_domain("foo.github.gov") | ||
assert_equal "github.gov", Gman::get_domain("http://github.gov") | ||
assert_equal "github.gov", Gman::get_domain("https://github.gov") | ||
assert_equal ".gov", Gman::get_domain(".gov") | ||
assert_equal nil, Gman.get_domain("foo") | ||
assert_equal "github.gov", Gman.new("[email protected]").domain | ||
assert_equal "foo.github.gov", Gman::new("foo.github.gov").domain | ||
assert_equal "github.gov", Gman::new("http://github.gov").domain | ||
assert_equal "github.gov", Gman::new("https://github.gov").domain | ||
assert_equal ".gov", Gman::new(".gov").domain | ||
assert_equal nil, Gman.new("foo").domain | ||
end | ||
|
||
should "not err out on invalid domains" do | ||
assert_equal false, Gman.valid?("[email protected]") | ||
assert_equal "gov.invalid", Gman.get_domain("[email protected]") | ||
assert_equal nil, Gman.domain_parts("[email protected]") | ||
assert_equal "gov.invalid", Gman.new("[email protected]").domain | ||
assert_equal nil, Gman.new("[email protected]").domain_parts | ||
end | ||
|
||
should "return public suffix domain" do | ||
assert_equal PublicSuffix::Domain, Gman.domain_parts("whitehouse.gov").class | ||
assert_equal NilClass, Gman.domain_parts("foo.invalid").class | ||
assert_equal PublicSuffix::Domain, Gman.new("whitehouse.gov").domain_parts.class | ||
assert_equal NilClass, Gman.new("foo.invalid").domain_parts.class | ||
end | ||
|
||
should "parse domain parts" do | ||
assert_equal "gov", Gman.domain_parts("[email protected]").tld | ||
assert_equal "bar", Gman.domain_parts("foo.bar.gov").sld | ||
assert_equal "bar", Gman.domain_parts("https://foo.bar.gov").sld | ||
assert_equal "bar.gov", Gman.domain_parts("[email protected]").domain | ||
assert_equal "gov", Gman.new("[email protected]").domain_parts.tld | ||
assert_equal "bar", Gman.new("foo.bar.gov").domain_parts.sld | ||
assert_equal "bar", Gman.new("https://foo.bar.gov").domain_parts.sld | ||
assert_equal "bar.gov", Gman.new("[email protected]").domain_parts.domain | ||
end | ||
|
||
should "not err out on invalid hosts" do | ||
assert_equal nil, Gman.get_domain("</@foo.com") | ||
assert_equal nil, Gman.new("</@foo.com").domain | ||
end | ||
|
||
should "returns the path to domains.txt" do | ||
assert_equal true, File.exists?(Gman.list_path) | ||
end | ||
|
||
should "parse the alpha2" do | ||
assert_equal "us", Gman.new("whitehouse.gov").alpha2 | ||
assert_equal "us", Gman.new("army.mil").alpha2 | ||
assert_equal "gb", Gman.new("foo.gov.uk").alpha2 | ||
assert_equal "ca", Gman.new("gov.ca").alpha2 | ||
end | ||
|
||
should "determine a domain's country" do | ||
assert_equal "United States", Gman.new("whitehouse.gov").country.name | ||
assert_equal "United States", Gman.new("army.mil").country.name | ||
assert_equal "United Kingdom", Gman.new("foo.gov.uk").country.name | ||
assert_equal "Canada", Gman.new("foo.gc.ca").country.name | ||
end | ||
end |