gman 7.0.0 → 7.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CODEOWNERS +3 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  5. data/.github/config.yml +23 -0
  6. data/.github/funding.yml +1 -0
  7. data/.github/no-response.yml +15 -0
  8. data/.github/release-drafter.yml +4 -0
  9. data/.github/settings.yml +33 -0
  10. data/.github/stale.yml +29 -0
  11. data/.gitignore +1 -0
  12. data/.rspec +2 -0
  13. data/.rubocop.yml +14 -5
  14. data/.rubocop_todo.yml +84 -0
  15. data/.ruby-version +1 -1
  16. data/Gemfile +2 -0
  17. data/bin/gman +6 -4
  18. data/bin/gman_filter +5 -7
  19. data/config/domains.txt +8454 -168
  20. data/config/vendor/academic.txt +6 -7
  21. data/config/vendor/dotgovs.csv +5786 -5560
  22. data/docs/CODE_OF_CONDUCT.md +46 -0
  23. data/docs/CONTRIBUTING.md +92 -0
  24. data/{README.md → docs/README.md} +3 -3
  25. data/docs/SECURITY.md +3 -0
  26. data/docs/_config.yml +2 -0
  27. data/gman.gemspec +18 -17
  28. data/lib/gman.rb +4 -2
  29. data/lib/gman/country_codes.rb +17 -17
  30. data/lib/gman/domain_list.rb +25 -9
  31. data/lib/gman/identifier.rb +57 -19
  32. data/lib/gman/importer.rb +31 -21
  33. data/lib/gman/locality.rb +8 -6
  34. data/lib/gman/version.rb +3 -1
  35. data/script/add +2 -0
  36. data/script/alphabetize +2 -0
  37. data/script/cibuild +1 -1
  38. data/script/dedupe +2 -1
  39. data/script/profile +2 -1
  40. data/script/prune +5 -3
  41. data/script/reconcile-us +6 -3
  42. data/script/vendor-federal-de +2 -1
  43. data/script/vendor-municipal-de +2 -1
  44. data/script/vendor-nl +2 -0
  45. data/script/vendor-public-suffix +6 -4
  46. data/script/vendor-se +2 -1
  47. data/script/vendor-swot +3 -1
  48. data/script/vendor-us +5 -3
  49. data/spec/fixtures/domains.txt +4 -0
  50. data/{test → spec}/fixtures/obama.txt +0 -0
  51. data/spec/gman/bin_spec.rb +101 -0
  52. data/spec/gman/country_code_spec.rb +39 -0
  53. data/spec/gman/domain_list_spec.rb +110 -0
  54. data/spec/gman/domains_spec.rb +25 -0
  55. data/spec/gman/identifier_spec.rb +218 -0
  56. data/spec/gman/importer_spec.rb +236 -0
  57. data/spec/gman/locality_spec.rb +24 -0
  58. data/spec/gman_spec.rb +74 -0
  59. data/spec/spec_helper.rb +31 -0
  60. metadata +89 -81
  61. data/.rake_tasks +0 -0
  62. data/CONTRIBUTING.md +0 -22
  63. data/Rakefile +0 -22
  64. data/test/fixtures/domains.txt +0 -2
  65. data/test/helper.rb +0 -48
  66. data/test/test_gman.rb +0 -56
  67. data/test/test_gman_bin.rb +0 -75
  68. data/test/test_gman_country_codes.rb +0 -18
  69. data/test/test_gman_domain_list.rb +0 -112
  70. data/test/test_gman_domains.rb +0 -32
  71. data/test/test_gman_filter.rb +0 -17
  72. data/test/test_gman_identifier.rb +0 -106
  73. data/test/test_gman_importer.rb +0 -244
  74. data/test/test_gman_locality.rb +0 -10
@@ -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`](../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 Gem
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
 
@@ -72,7 +72,7 @@ domain.country.name #=> "United States"
72
72
  domain.country.alpha2 #=> "US"
73
73
  domain.country.alpha3 #=> "USA"
74
74
  domain.country.currency #=> "USD"
75
- domain.conutry.calling_code #=> "+1"
75
+ domain.country.calling_code #=> "+1"
76
76
  ```
77
77
 
78
78
  ### Check if a country is on the US Sanctions list
@@ -0,0 +1,3 @@
1
+ # Security Policy
2
+
3
+ To report a security vulnerability, please email [ben@balter.com](mailto:ben@balter.com).
@@ -0,0 +1,2 @@
1
+ title: Gman
2
+ description: A ruby gem to verify if the owner of a given email address, website, or domain is a government agency.
@@ -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 = <<-EOF
7
+ s.summary = <<-SUMMARY
6
8
  Check if a given domain or email address belong to a governemnt entity
7
- EOF
8
- s.description = <<-EOF
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
- EOF
13
+ DESC
12
14
  s.version = Gman::VERSION
13
15
  s.authors = ['Ben Balter']
14
16
  s.email = 'ben.balter@github.com'
@@ -20,24 +22,23 @@ 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.0'
27
+ s.required_ruby_version = '~> 2.5'
27
28
 
28
- s.add_dependency('iso_country_codes', '~> 0.6')
29
- s.add_dependency('naughty_or_nice', '~> 2.0')
30
29
  s.add_dependency('colored', '~> 1.2')
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')
31
33
 
32
- s.add_development_dependency('swot', '~> 1.0')
33
- s.add_development_dependency('rake', '~> 10.4')
34
- s.add_development_dependency('shoulda', '~> 3.5')
35
- s.add_development_dependency('rdoc', '~> 4.2')
36
- s.add_development_dependency('bundler', '~> 1.10')
37
- s.add_development_dependency('pry', '~> 0.10')
38
- s.add_development_dependency('parallel', '~> 1.6')
39
- s.add_development_dependency('mechanize', '~> 2.7')
40
34
  s.add_development_dependency('addressable', '~> 2.3')
35
+ s.add_development_dependency('mechanize', '~> 2.7')
36
+ s.add_development_dependency('parallel', '~> 1.6')
37
+ s.add_development_dependency('pry', '~> 0.10')
38
+ s.add_development_dependency('rspec', '~> 3.5')
39
+ s.add_development_dependency('rubocop', '~> 1.0')
40
+ s.add_development_dependency('rubocop-performance', '~> 1.5')
41
+ s.add_development_dependency('rubocop-rspec', '~> 2.0')
41
42
  s.add_development_dependency('ruby-prof', '~> 0.15')
42
- s.add_development_dependency('rubocop', '~> 0.37')
43
+ s.add_development_dependency('swot', '~> 1.0')
43
44
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
4
 
3
5
  require 'naughty_or_nice'
4
- require 'swot'
5
6
  require 'iso_country_codes'
6
7
  require 'csv'
7
8
  require_relative 'gman/version'
@@ -45,6 +46,7 @@ class Gman
45
46
  @valid ||= begin
46
47
  return false unless valid_domain?
47
48
  return false if academic?
49
+
48
50
  locality? || public_suffix_valid?
49
51
  end
50
52
  end
@@ -56,7 +58,7 @@ class Gman
56
58
  private
57
59
 
58
60
  def valid_domain?
59
- @valid_domains ||= domain && domain.valid? && !academic?
61
+ @valid_domain ||= !domain.nil? && !academic?
60
62
  end
61
63
 
62
64
  def academic?
@@ -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: 'sh',
5
- uk: 'gb',
6
- su: 'ru',
7
- tp: 'tl',
8
- yu: 'rs',
9
- gov: 'us',
10
- mil: 'us',
11
- org: 'us',
12
- com: 'us',
13
- net: 'us',
14
- edu: 'us',
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: 'us'
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
- if ALPHA2_MAP[alpha2.to_sym]
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,6 +37,7 @@ 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
43
  rescue IsoCountryCodes::UnknownCodeError
@@ -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
 
@@ -58,12 +60,10 @@ class Gman
58
60
  @public_suffix_list ||= PublicSuffix::List.parse(contents)
59
61
  end
60
62
 
61
- # domain is on the domain list and
62
- # domain is not explicitly blacklisted and
63
- # domain matches a standard public suffix list rule
63
+ # domain is on the domain list
64
64
  def valid?(domain)
65
- rule = public_suffix_list.find(domain)
66
- !rule.nil? && rule.type != :exception && rule.allow?(".#{domain}")
65
+ rule = public_suffix_list.find(domain, default: nil)
66
+ !(rule.nil? || rule.is_a?(PublicSuffix::Rule::Exception))
67
67
  end
68
68
 
69
69
  # Returns an array of strings representing the list groups
@@ -82,9 +82,13 @@ class Gman
82
82
  end
83
83
 
84
84
  # Alphabetize groups and domains within each group
85
+ # We need to ensure exceptions appear after their coresponding rules
85
86
  def alphabetize
86
87
  @data = data.sort_by { |k, _v| k.downcase }.to_h
87
- @data.each { |_group, domains| domains.sort!.uniq! }
88
+ @data.map do |_group, domains|
89
+ domains.sort! { |a, b| sort_with_exceptions(a, b) }
90
+ domains.uniq!
91
+ end
88
92
  end
89
93
 
90
94
  # Write the domain list to disk
@@ -95,7 +99,7 @@ class Gman
95
99
 
96
100
  # The string representation of the domain list, in public suffix format
97
101
  def to_s
98
- current_group = output = ''
102
+ current_group = output = +''
99
103
  data.sort_by { |group, _| group.downcase }.each do |group, domains|
100
104
  if group != current_group
101
105
  output << "\n\n" unless current_group.empty? # first entry
@@ -119,6 +123,7 @@ class Gman
119
123
  # Parse a public-suffix formatted string into a hash of groups => [domains]
120
124
  def string_to_hash(string)
121
125
  return unless string
126
+
122
127
  lines = string_to_array(string)
123
128
  array_to_hash(lines)
124
129
  end
@@ -131,7 +136,7 @@ class Gman
131
136
  domain_hash = {}
132
137
  group = ''
133
138
  lines.each do |line|
134
- if line =~ COMMENT_REGEX
139
+ if COMMENT_REGEX.match?(line)
135
140
  group = COMMENT_REGEX.match(line)[1]
136
141
  else
137
142
  safe_push(domain_hash, group, line.downcase)
@@ -146,8 +151,19 @@ class Gman
146
151
  # value - the single value to push into the array at hash[key]
147
152
  def safe_push(hash, key, value)
148
153
  return if value.empty?
154
+
149
155
  hash[key] ||= []
150
156
  hash[key].push value
151
157
  end
158
+
159
+ def sort_with_exceptions(left, right)
160
+ if left.start_with?('!') && !right.start_with?('!')
161
+ 1
162
+ elsif right.start_with?('!') && !left.start_with?('!')
163
+ -1
164
+ else
165
+ left <=> right
166
+ end
167
+ end
152
168
  end
153
169
  end
@@ -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
- [:state, :district, :cog, :city, :federal, :county].each do |type|
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
- dotgov_listing && dotgov_listing['Domain Type'] == 'Federal Agency'
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(ci town vil).include?(matches[3])
68
+ %w[ci town vil].include?(matches[3])
44
69
  elsif dotgov_listing
45
- dotgov_listing['Domain Type'] == 'City'
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
- dotgov_listing['Domain Type'] == 'County'
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
- dotgov_listing['Domain Type'] == 'State/Local Govt'
90
+ domain_type == 'State/Local Govt'
91
+ else
92
+ false
62
93
  end
63
94
  end
64
95
 
65
96
  def district?
66
- matches && matches[1] == 'dst'
97
+ return false unless matches
98
+
99
+ matches[1] == 'dst'
67
100
  end
68
101
 
69
102
  def cog?
70
- matches && matches[1] == 'cog'
103
+ return false unless matches
104
+
105
+ matches[1] == 'cog'
71
106
  end
72
107
 
73
108
  private
@@ -76,7 +111,8 @@ class Gman
76
111
  @list_category ||= begin
77
112
  match = Gman.list.public_suffix_list.find(domain.to_s)
78
113
  return unless match
79
- regex = %r{// ([^\n]+)\n?[^/]*\n#{Regexp.escape(match.name)}\n}im
114
+
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
82
118
  end
@@ -84,14 +120,16 @@ 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
- listing['Domain Name'].casecmp("#{domain.sld}.gov") == 0
132
+ listing['Domain Name'].casecmp("#{domain.sld}.gov").zero?
95
133
  end
96
134
  end
97
135