gman 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/gman.gemspec +1 -1
  2. data/lib/gman.rb +15 -2
  3. data/test/test_gman.rb +18 -0
  4. metadata +2 -2
data/gman.gemspec CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
2
2
  s.name = "gman"
3
3
  s.summary = "Check if a given domain or email address belong to a governemnt entity"
4
4
  s.description = "A ruby gem to check if the owner of a given email address is working for THE MAN."
5
- s.version = "0.1.0"
5
+ s.version = "0.2.0"
6
6
  s.authors = ["Ben Balter"]
7
7
  s.email = "ben.balter@github.com"
8
8
  s.homepage = "https://github.com/benbalter/gman"
data/lib/gman.rb CHANGED
@@ -52,9 +52,9 @@ module Gman
52
52
  # Returns a string with the FQDN; nil if there's an error.
53
53
  def get_domain(text)
54
54
 
55
- return nil if text.to_s.empty?
55
+ return nil if text.to_s.strip.empty?
56
56
 
57
- text = text.downcase
57
+ text = text.downcase.strip
58
58
  uri = Addressable::URI.parse(text)
59
59
 
60
60
  if uri.host # valid https?://* URI
@@ -69,6 +69,19 @@ module Gman
69
69
  end
70
70
  end
71
71
 
72
+ # Helper function to return the public suffix domain object
73
+ #
74
+ # Supports all domainy strings (URLs, emails)
75
+ #
76
+ # Returns the domain object or nil, but no errors, never an error
77
+ def domain_parts(text)
78
+ begin
79
+ PublicSuffix.parse get_domain(text)
80
+ rescue
81
+ nil
82
+ end
83
+ end
84
+
72
85
  # Is the given string in the form of a valid email address?
73
86
  #
74
87
  # Returns true if email, otherwise false
data/test/test_gman.rb CHANGED
@@ -22,6 +22,7 @@ INVALID = [ "foo.bar.com",
22
22
  "foo",
23
23
  "",
24
24
  nil,
25
+ " ",
25
26
  ]
26
27
 
27
28
  class TestGman < Test::Unit::TestCase
@@ -87,4 +88,21 @@ class TestGman < Test::Unit::TestCase
87
88
  end
88
89
  end
89
90
 
91
+ should "not err out on invalid domains" do
92
+ assert_equal false, Gman.valid?("foo@act.gov.au")
93
+ assert_equal "act.gov.au", Gman.get_domain("foo@act.gov.au")
94
+ assert_equal nil, Gman.domain_parts("foo@act.gov.au")
95
+ end
96
+
97
+ should "return public suffix domain" do
98
+ assert_equal PublicSuffix::Domain, Gman.domain_parts("whitehouse.gov").class
99
+ assert_equal NilClass, Gman.domain_parts("foo.bar").class
100
+ end
101
+
102
+ should "parse domain parts" do
103
+ assert_equal "gov", Gman.domain_parts("foo@bar.gov").tld
104
+ assert_equal "bar", Gman.domain_parts("foo.bar.gov").sld
105
+ assert_equal "bar", Gman.domain_parts("https://foo.bar.gov").sld
106
+ assert_equal "bar.gov", Gman.domain_parts("foo@bar.gov").domain
107
+ end
90
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-27 00:00:00.000000000 Z
12
+ date: 2013-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: public_suffix