gman 7.0.2 → 7.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
- data/.github/config.yml +23 -0
- data/.github/no-response.yml +15 -0
- data/.github/release-drafter.yml +4 -0
- data/.github/settings.yml +33 -0
- data/.github/stale.yml +29 -0
- data/.rubocop.yml +5 -5
- data/.ruby-version +1 -1
- data/Gemfile +2 -0
- data/bin/gman +3 -1
- data/bin/gman_filter +3 -5
- data/config/domains.txt +191 -134
- data/config/vendor/dotgovs.csv +5786 -5634
- data/docs/CODE_OF_CONDUCT.md +46 -0
- data/docs/CONTRIBUTING.md +92 -0
- data/{README.md → docs/README.md} +2 -2
- data/docs/_config.yml +2 -0
- data/gman.gemspec +16 -15
- data/lib/gman.rb +4 -1
- data/lib/gman/country_codes.rb +19 -19
- data/lib/gman/domain_list.rb +10 -6
- data/lib/gman/identifier.rb +55 -17
- data/lib/gman/importer.rb +27 -18
- data/lib/gman/locality.rb +8 -6
- data/lib/gman/version.rb +3 -1
- data/script/add +2 -0
- data/script/alphabetize +2 -0
- data/script/dedupe +1 -0
- data/script/profile +1 -0
- data/script/prune +5 -3
- data/script/reconcile-us +5 -2
- data/script/vendor-federal-de +2 -1
- data/script/vendor-municipal-de +2 -1
- data/script/vendor-nl +2 -0
- data/script/vendor-public-suffix +3 -1
- data/script/vendor-se +1 -0
- data/script/vendor-swot +2 -0
- data/script/vendor-us +4 -2
- data/spec/gman/bin_spec.rb +8 -6
- data/spec/gman/country_code_spec.rb +6 -4
- data/spec/gman/domain_list_spec.rb +3 -1
- data/spec/gman/domains_spec.rb +3 -0
- data/spec/gman/identifier_spec.rb +38 -3
- data/spec/gman/importer_spec.rb +9 -7
- data/spec/gman/locality_spec.rb +2 -0
- data/spec/gman_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +52 -44
- data/CONTRIBUTING.md +0 -22
- data/contributing.json +0 -32
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ben@balter.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# Contributing to Gman
|
2
|
+
|
3
|
+
Hi there! We're thrilled that you'd like to contribute to Gman. Your help is essential for keeping it great.
|
4
|
+
|
5
|
+
Gman is an open source project supported by the efforts of an entire community and built one contribution at a time by users like you. We'd love for you to get involved. Whatever your level of skill or however much time you can give, your contribution is greatly appreciated. There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests, helping other users by commenting on issues, or writing code which can be incorporated into Gman itself.
|
6
|
+
|
7
|
+
Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue, assessing changes, and helping you finalize your pull requests.
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
## How to report a bug
|
12
|
+
|
13
|
+
Think you found a bug? Please check [the list of open issues](https://github.com/benbalter/gman/issues) to see if your bug has already been reported. If it hasn't please [submit a new issue](https://github.com/benbalter/gman/issues/new).
|
14
|
+
|
15
|
+
Here are a few tips for writing *great* bug reports:
|
16
|
+
|
17
|
+
* Describe the specific problem (e.g., "widget doesn't turn clockwise" versus "getting an error")
|
18
|
+
* Include the steps to reproduce the bug, what you expected to happen, and what happened instead
|
19
|
+
* Check that you are using the latest version of the project and its dependencies
|
20
|
+
* Include what version of the project your using, as well as any relevant dependencies
|
21
|
+
* Only include one bug per issue. If you have discovered two bugs, please file two issues
|
22
|
+
* Include screenshots or screencasts whenever possible
|
23
|
+
* Even if you don't know how to fix the bug, including a failing test may help others track it down
|
24
|
+
|
25
|
+
**If you find a security vulnerability, do not open an issue. Please email ben@balter.com instead.**
|
26
|
+
|
27
|
+
## How to suggest a feature or enhancement
|
28
|
+
|
29
|
+
If you find yourself wishing for a feature that doesn't exist in Gman, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Gman has today have been added because our users saw the need.
|
30
|
+
|
31
|
+
Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and goals of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible, including describing the problem you're trying to solve.
|
32
|
+
|
33
|
+
[Open an issue](https://github.com/benbalter/gman/issues/new) which describes the feature you would like to see, why you want it, how it should work, etc.
|
34
|
+
|
35
|
+
## Domains
|
36
|
+
|
37
|
+
Domains live in `./config/domains.txt` as a list of TLDs and SLD+TLDs.
|
38
|
+
|
39
|
+
Right now, the only valid government top level domains (TLDs), represent the US government and are `.gov`, and `.mil`. Secondary domains (e.g., `gov.uk`, or `mil.au`) represent non-US government entities.
|
40
|
+
|
41
|
+
To add or remove a domain from the list of known government domains, simply edit the `domains.txt` file.
|
42
|
+
|
43
|
+
|
44
|
+
## Your first contribution
|
45
|
+
|
46
|
+
We'd love for you to contribute to the project. Unsure where to begin contributing to Gman? You can start by looking through these "good first issue" and "help wanted" issues:
|
47
|
+
|
48
|
+
* [Good first issues](https://github.com/benbalter/gman/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) - issues which should only require a few lines of code and a test or two
|
49
|
+
* [Help wanted issues](https://github.com/benbalter/gman/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) - issues which may be a bit more involved, but are specifically seeking community contributions
|
50
|
+
|
51
|
+
*p.s. Feel free to ask for help; everyone is a beginner at first* :smiley_cat:
|
52
|
+
|
53
|
+
## How to propose changes
|
54
|
+
|
55
|
+
Here's a few general guidelines for proposing changes:
|
56
|
+
|
57
|
+
* If you are changing any user-facing functionality, please be sure to update the documentation
|
58
|
+
* If you are adding a new behavior or changing an existing behavior, please be sure to update the corresponding test(s)
|
59
|
+
* Each pull request should implement **one** feature or bug fix. If you want to add or fix more than one thing, submit more than one pull request
|
60
|
+
* Do not commit changes to files that are irrelevant to your feature or bug fix
|
61
|
+
* Don't bump the version number in your pull request (it will be bumped prior to release)
|
62
|
+
* Write [a good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
|
63
|
+
|
64
|
+
At a high level, [the process for proposing changes](https://guides.github.com/introduction/flow/) is:
|
65
|
+
|
66
|
+
1. [Fork](https://github.com/benbalter/gman/fork) and clone the project
|
67
|
+
2. Configure and install the dependencies: `script/bootstrap`
|
68
|
+
3. Make sure the tests pass on your machine: `script/cibuild`
|
69
|
+
4. Create a descriptively named branch: `git checkout -b my-branch-name`
|
70
|
+
5. Make your change, add tests and documentation, and make sure the tests still pass
|
71
|
+
6. Push to your fork and [submit a pull request](https://github.com/benbalter/gman/compare) describing your change
|
72
|
+
7. Pat your self on the back and wait for your pull request to be reviewed and merged
|
73
|
+
|
74
|
+
**Interesting in submitting your first Pull Request?** It's easy! You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)
|
75
|
+
|
76
|
+
## Bootstrapping your local development environment
|
77
|
+
|
78
|
+
`script/bootstrap`
|
79
|
+
|
80
|
+
## Running tests
|
81
|
+
|
82
|
+
`script/cibuild`
|
83
|
+
|
84
|
+
## Code of conduct
|
85
|
+
|
86
|
+
This project is governed by [the Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
|
87
|
+
|
88
|
+
## Additional Resources
|
89
|
+
|
90
|
+
* [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/)
|
91
|
+
* [Using Pull Requests](https://help.github.com/articles/using-pull-requests/)
|
92
|
+
* [GitHub Help](https://help.github.com)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
# Gman
|
1
|
+
# Gman
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/benbalter/gman.png)](https://travis-ci.org/benbalter/gman) [![Gem Version](https://badge.fury.io/rb/gman.png)](http://badge.fury.io/rb/gman)
|
3
|
+
[![Build Status](https://travis-ci.org/benbalter/gman.png)](https://travis-ci.org/benbalter/gman) [![Gem Version](https://badge.fury.io/rb/gman.png)](http://badge.fury.io/rb/gman) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
|
4
4
|
|
5
5
|
A ruby gem to check if the owner of a given email address or website is working for THE MAN (a.k.a verifies government domains). It will also provide you with metadata about the domain, such as the country, state, city, or agency, where applicable. It does this by leveraging the power of [Naughty or Nice](https://github.com/benbalter/naughty_or_nice), the [Public Suffix List](http://publicsuffix.org/), and the associated [Ruby Gem](https://github.com/weppos/publicsuffix-ruby).
|
6
6
|
|
data/docs/_config.yml
ADDED
data/gman.gemspec
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path './lib/gman/version', File.dirname(__FILE__)
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.name = 'gman'
|
5
|
-
s.summary = <<-
|
7
|
+
s.summary = <<-SUMMARY
|
6
8
|
Check if a given domain or email address belong to a governemnt entity
|
7
|
-
|
8
|
-
s.description = <<-
|
9
|
+
SUMMARY
|
10
|
+
s.description = <<-DESC
|
9
11
|
A ruby gem to check if the owner of a given email address is working for
|
10
12
|
THE MAN.
|
11
|
-
|
13
|
+
DESC
|
12
14
|
s.version = Gman::VERSION
|
13
15
|
s.authors = ['Ben Balter']
|
14
16
|
s.email = 'ben.balter@github.com'
|
@@ -20,22 +22,21 @@ Gem::Specification.new do |s|
|
|
20
22
|
s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
|
21
23
|
File.basename(f)
|
22
24
|
end
|
23
|
-
s.require_paths = ['lib']
|
24
25
|
|
25
26
|
s.require_paths = ['lib']
|
26
|
-
s.required_ruby_version = '~> 2.
|
27
|
+
s.required_ruby_version = '~> 2.3'
|
27
28
|
|
28
|
-
s.add_dependency('iso_country_codes', '~> 0.6')
|
29
|
-
s.add_dependency('naughty_or_nice', '= 2.1')
|
30
29
|
s.add_dependency('colored', '~> 1.2')
|
31
|
-
s.add_dependency('
|
30
|
+
s.add_dependency('iso_country_codes', '~> 0.6')
|
31
|
+
s.add_dependency('naughty_or_nice', '= 2.1.1')
|
32
|
+
s.add_dependency('public_suffix', '~> 3.0')
|
32
33
|
|
33
|
-
s.add_development_dependency('swot', '~> 1.0')
|
34
|
-
s.add_development_dependency('pry', '~> 0.10')
|
35
|
-
s.add_development_dependency('parallel', '~> 1.6')
|
36
|
-
s.add_development_dependency('mechanize', '~> 2.7')
|
37
34
|
s.add_development_dependency('addressable', '~> 2.3')
|
38
|
-
s.add_development_dependency('
|
39
|
-
s.add_development_dependency('
|
35
|
+
s.add_development_dependency('mechanize', '~> 2.7')
|
36
|
+
s.add_development_dependency('parallel', '~> 1.6')
|
37
|
+
s.add_development_dependency('pry', '~> 0.10')
|
40
38
|
s.add_development_dependency('rspec', '~> 3.5')
|
39
|
+
s.add_development_dependency('rubocop', '~> 0.37')
|
40
|
+
s.add_development_dependency('ruby-prof', '~> 0.15')
|
41
|
+
s.add_development_dependency('swot', '~> 1.0')
|
41
42
|
end
|
data/lib/gman.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
4
|
|
3
5
|
require 'naughty_or_nice'
|
@@ -44,6 +46,7 @@ class Gman
|
|
44
46
|
@valid ||= begin
|
45
47
|
return false unless valid_domain?
|
46
48
|
return false if academic?
|
49
|
+
|
47
50
|
locality? || public_suffix_valid?
|
48
51
|
end
|
49
52
|
end
|
@@ -55,7 +58,7 @@ class Gman
|
|
55
58
|
private
|
56
59
|
|
57
60
|
def valid_domain?
|
58
|
-
@
|
61
|
+
@valid_domain ||= !domain.nil? && !academic?
|
59
62
|
end
|
60
63
|
|
61
64
|
def academic?
|
data/lib/gman/country_codes.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Gman
|
2
4
|
# Map last part of TLD to alpha2 country code
|
3
5
|
ALPHA2_MAP = {
|
4
|
-
ac:
|
5
|
-
uk:
|
6
|
-
su:
|
7
|
-
tp:
|
8
|
-
yu:
|
9
|
-
gov:
|
10
|
-
mil:
|
11
|
-
org:
|
12
|
-
com:
|
13
|
-
net:
|
14
|
-
edu:
|
6
|
+
ac: 'sh',
|
7
|
+
uk: 'gb',
|
8
|
+
su: 'ru',
|
9
|
+
tp: 'tl',
|
10
|
+
yu: 'rs',
|
11
|
+
gov: 'us',
|
12
|
+
mil: 'us',
|
13
|
+
org: 'us',
|
14
|
+
com: 'us',
|
15
|
+
net: 'us',
|
16
|
+
edu: 'us',
|
15
17
|
travel: 'us',
|
16
|
-
info:
|
18
|
+
info: 'us'
|
17
19
|
}.freeze
|
18
20
|
|
19
21
|
# Returns the two character alpha county code represented by the domain
|
@@ -21,13 +23,10 @@ class Gman
|
|
21
23
|
# e.g., United States = US, United Kingdom = GB
|
22
24
|
def alpha2
|
23
25
|
return unless domain
|
26
|
+
|
24
27
|
@alpha2 ||= begin
|
25
28
|
alpha2 = domain.tld.split('.').last
|
26
|
-
|
27
|
-
ALPHA2_MAP[alpha2.to_sym]
|
28
|
-
else
|
29
|
-
alpha2
|
30
|
-
end
|
29
|
+
ALPHA2_MAP[alpha2.to_sym] || alpha2
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
@@ -38,10 +37,11 @@ class Gman
|
|
38
37
|
# Gman.new("foo.gov").country.currency => "USD"
|
39
38
|
def country
|
40
39
|
return @country if defined? @country
|
40
|
+
|
41
41
|
@country ||= begin
|
42
42
|
IsoCountryCodes.find(alpha2) if alpha2
|
43
|
-
|
44
|
-
|
43
|
+
rescue IsoCountryCodes::UnknownCodeError
|
44
|
+
nil
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/lib/gman/domain_list.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Gman
|
2
4
|
class DomainList
|
3
|
-
COMMENT_REGEX = %r{//[/\s]*(.*)$}i
|
5
|
+
COMMENT_REGEX = %r{//[/\s]*(.*)$}i.freeze
|
4
6
|
|
5
7
|
attr_writer :data, :path, :contents
|
6
8
|
|
@@ -97,7 +99,7 @@ class Gman
|
|
97
99
|
|
98
100
|
# The string representation of the domain list, in public suffix format
|
99
101
|
def to_s
|
100
|
-
current_group = output = ''
|
102
|
+
current_group = output = +''
|
101
103
|
data.sort_by { |group, _| group.downcase }.each do |group, domains|
|
102
104
|
if group != current_group
|
103
105
|
output << "\n\n" unless current_group.empty? # first entry
|
@@ -121,6 +123,7 @@ class Gman
|
|
121
123
|
# Parse a public-suffix formatted string into a hash of groups => [domains]
|
122
124
|
def string_to_hash(string)
|
123
125
|
return unless string
|
126
|
+
|
124
127
|
lines = string_to_array(string)
|
125
128
|
array_to_hash(lines)
|
126
129
|
end
|
@@ -148,17 +151,18 @@ class Gman
|
|
148
151
|
# value - the single value to push into the array at hash[key]
|
149
152
|
def safe_push(hash, key, value)
|
150
153
|
return if value.empty?
|
154
|
+
|
151
155
|
hash[key] ||= []
|
152
156
|
hash[key].push value
|
153
157
|
end
|
154
158
|
|
155
|
-
def sort_with_exceptions(
|
156
|
-
if
|
159
|
+
def sort_with_exceptions(left, right)
|
160
|
+
if left.start_with?('!') && !right.start_with?('!')
|
157
161
|
1
|
158
|
-
elsif
|
162
|
+
elsif right.start_with?('!') && !left.start_with?('!')
|
159
163
|
-1
|
160
164
|
else
|
161
|
-
|
165
|
+
left <=> right
|
162
166
|
end
|
163
167
|
end
|
164
168
|
end
|
data/lib/gman/identifier.rb
CHANGED
@@ -1,9 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Gman
|
4
|
+
# Defines an instance method that delegates to a hash's key
|
5
|
+
#
|
6
|
+
# hash_method - a symbol representing the instance method to delegate to. The
|
7
|
+
# instance method should return a hash or respond to #[]
|
8
|
+
# key - the key to call within the hash
|
9
|
+
# method - (optional) the instance method the key should be aliased to.
|
10
|
+
# If not specified, defaults to the hash key
|
11
|
+
# default - (optional) value to return if value is nil (defaults to nil)
|
12
|
+
#
|
13
|
+
# Returns a symbol representing the instance method
|
14
|
+
def self.def_hash_delegator(hash_method, key, method = nil, default = nil)
|
15
|
+
method ||= key.to_s.downcase.sub(' ', '_')
|
16
|
+
define_method(method) do
|
17
|
+
hash = send(hash_method)
|
18
|
+
if hash.respond_to? :[]
|
19
|
+
hash[key.to_s] || default
|
20
|
+
else
|
21
|
+
default
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def_hash_delegator :dotgov_listing, :Agency
|
27
|
+
def_hash_delegator :dotgov_listing, :Organization
|
28
|
+
def_hash_delegator :dotgov_listing, :City
|
29
|
+
def_hash_delegator :dotgov_listing, :"Domain Type"
|
30
|
+
private :domain_type
|
31
|
+
|
2
32
|
def type
|
3
|
-
[
|
33
|
+
%i[state district cog city federal county].each do |type|
|
4
34
|
return type if send "#{type}?"
|
5
35
|
end
|
6
36
|
return if list_category.nil?
|
37
|
+
|
7
38
|
if list_category.include?('usagov')
|
8
39
|
:unknown
|
9
40
|
else
|
@@ -14,7 +45,7 @@ class Gman
|
|
14
45
|
def state
|
15
46
|
if matches
|
16
47
|
matches[4].upcase
|
17
|
-
elsif dotgov_listing
|
48
|
+
elsif dotgov_listing['State']
|
18
49
|
dotgov_listing['State']
|
19
50
|
elsif list_category
|
20
51
|
matches = list_category.match(/usagov([A-Z]{2})/)
|
@@ -22,27 +53,23 @@ class Gman
|
|
22
53
|
end
|
23
54
|
end
|
24
55
|
|
25
|
-
def city
|
26
|
-
dotgov_listing['City'] if dotgov_listing
|
27
|
-
end
|
28
|
-
|
29
|
-
def agency
|
30
|
-
dotgov_listing['Agency'] if federal?
|
31
|
-
end
|
32
|
-
|
33
56
|
def dotgov?
|
34
57
|
domain.tld == 'gov'
|
35
58
|
end
|
36
59
|
|
37
60
|
def federal?
|
38
|
-
|
61
|
+
return false unless dotgov_listing
|
62
|
+
|
63
|
+
domain_type =~ /^Federal Agency/i
|
39
64
|
end
|
40
65
|
|
41
66
|
def city?
|
42
67
|
if matches
|
43
|
-
%w
|
68
|
+
%w[ci town vil].include?(matches[3])
|
44
69
|
elsif dotgov_listing
|
45
|
-
|
70
|
+
domain_type == 'City'
|
71
|
+
else
|
72
|
+
false
|
46
73
|
end
|
47
74
|
end
|
48
75
|
|
@@ -50,7 +77,9 @@ class Gman
|
|
50
77
|
if matches
|
51
78
|
matches[3] == 'co'
|
52
79
|
elsif dotgov_listing
|
53
|
-
|
80
|
+
domain_type == 'County'
|
81
|
+
else
|
82
|
+
false
|
54
83
|
end
|
55
84
|
end
|
56
85
|
|
@@ -58,16 +87,22 @@ class Gman
|
|
58
87
|
if matches
|
59
88
|
matches[1] == 'state'
|
60
89
|
elsif dotgov_listing
|
61
|
-
|
90
|
+
domain_type == 'State/Local Govt'
|
91
|
+
else
|
92
|
+
false
|
62
93
|
end
|
63
94
|
end
|
64
95
|
|
65
96
|
def district?
|
66
|
-
|
97
|
+
return false unless matches
|
98
|
+
|
99
|
+
matches[1] == 'dst'
|
67
100
|
end
|
68
101
|
|
69
102
|
def cog?
|
70
|
-
|
103
|
+
return false unless matches
|
104
|
+
|
105
|
+
matches[1] == 'cog'
|
71
106
|
end
|
72
107
|
|
73
108
|
private
|
@@ -76,6 +111,7 @@ class Gman
|
|
76
111
|
@list_category ||= begin
|
77
112
|
match = Gman.list.public_suffix_list.find(domain.to_s)
|
78
113
|
return unless match
|
114
|
+
|
79
115
|
regex = %r{// ([^\n]+)\n?[^/]*\n#{Regexp.escape(match.value)}\n}im
|
80
116
|
matches = Gman.list.contents.match(regex)
|
81
117
|
matches[1] if matches
|
@@ -84,12 +120,14 @@ class Gman
|
|
84
120
|
|
85
121
|
def matches
|
86
122
|
return @matches if defined? @matches
|
123
|
+
|
87
124
|
@matches = domain.to_s.match(Locality::REGEX)
|
88
125
|
end
|
89
126
|
|
90
127
|
def dotgov_listing
|
91
128
|
return @dotgov_listing if defined? @dotgov_listing
|
92
129
|
return unless dotgov?
|
130
|
+
|
93
131
|
@dotgov_listing = Gman.dotgov_list.find do |listing|
|
94
132
|
listing['Domain Name'].casecmp("#{domain.sld}.gov").zero?
|
95
133
|
end
|