naughty_or_nice 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c399a91caa2bee04c314ade13bbd8ffde58c92a
4
- data.tar.gz: 87a27c60c85e5d83779d3741cb49e1dedecc95dd
3
+ metadata.gz: c1f0a6ca903c8a3019b9e566099f6454b1d2b941
4
+ data.tar.gz: daf9330f225766d7d2bdedee264d6d98a8bcc39f
5
5
  SHA512:
6
- metadata.gz: 3f870a6c26daea2e31c516197b81db790f0290628d6e0954ed70d0a9b2ef954c80d4607c135277c46bf837b3526b97c960a3e5428ce77299a5529d75c0f62673
7
- data.tar.gz: 4e885f710f2cf71b2155a4ecc9b3c46651976938d179b03fde50bde94544c2fd395243f0944d7ad080b55acebf27786ece8059b33799b0d38b0ac132bf958b62
6
+ metadata.gz: 2e0f1f7f05521e3c08f124f28513e3f8a19c752d84dc96288793a48f58aaa8493876cda29d34a31c1e3acbe3a4c0284a9f77689aa116f880335262a32ae96ba6
7
+ data.tar.gz: bc06c3ed9f60e07525e016f80bb7ff23f15f0307712b06d6b6142a873311a043e1792b9bc63d7fa66e365569d4f58f88e941daf3d0475da8e054e190fba34f00
data/README.md CHANGED
@@ -36,7 +36,7 @@ class Checker
36
36
  include NaughtyOrNice
37
37
 
38
38
  def valid?
39
- domain.tld == ".gov"
39
+ domain.tld == "gov"
40
40
  end
41
41
  end
42
42
  ```
@@ -1,9 +1,9 @@
1
1
  require 'public_suffix'
2
- require "addressable/uri"
2
+ require 'addressable/uri'
3
3
  require_relative './naughty_or_nice/version'
4
4
 
5
+ # Primary module to be mixed into the child class
5
6
  module NaughtyOrNice
6
-
7
7
  # Source: http://bit.ly/1n2X9iv
8
8
  EMAIL_REGEX = %r{
9
9
  ^
@@ -43,13 +43,13 @@ module NaughtyOrNice
43
43
  $
44
44
  }xi
45
45
 
46
+ # Ruby idiom that allows `include` to create class methods
46
47
  module ClassMethods
47
48
  def valid?(text)
48
- self.new(text).valid?
49
+ new(text).valid?
49
50
  end
50
51
  end
51
52
 
52
- # Ruby idiom that allows `include` to create class methods
53
53
  def self.included(base)
54
54
  base.extend(ClassMethods)
55
55
  end
@@ -70,9 +70,9 @@ module NaughtyOrNice
70
70
  # Returns the domain object or nil, but no errors, never an error
71
71
  def domain
72
72
  return @domain if defined? @domain
73
-
73
+
74
74
  @domain = begin
75
- PublicSuffix.parse(domain_text)
75
+ PublicSuffix.parse(normalized_domain, default_rule: nil)
76
76
  rescue PublicSuffix::DomainInvalid, PublicSuffix::DomainNotAllowed
77
77
  nil
78
78
  end
@@ -82,14 +82,14 @@ module NaughtyOrNice
82
82
  #
83
83
  # Returns boolean true if a valid domain, otherwise false
84
84
  def valid?
85
- !!(domain && domain.valid?)
85
+ !domain.nil?
86
86
  end
87
87
 
88
88
  # Is the input text in the form of a valid email address?
89
89
  #
90
90
  # Returns true if email, otherwise false
91
91
  def email?
92
- !!(@text =~ EMAIL_REGEX)
92
+ !(@text =~ EMAIL_REGEX).nil?
93
93
  end
94
94
 
95
95
  # Return the parsed domain as a string
@@ -108,20 +108,22 @@ module NaughtyOrNice
108
108
  # Can handle urls, domains, or emails
109
109
  #
110
110
  # Returns the domain string
111
- def domain_text
112
- return nil if @text.empty?
113
-
114
- uri = Addressable::URI.parse(@text)
111
+ def normalized_domain
112
+ if @text.empty?
113
+ nil
114
+ elsif parsed_domain
115
+ parsed_domain.host
116
+ end
117
+ end
115
118
 
116
- if uri.host # valid https?://* URI
117
- uri.host
118
- elsif email?
119
- @text.match(/@([\w\.\-]+)\Z/i)[1]
120
- else # url sans http://
121
- uri = Addressable::URI.parse("http://#{@text}")
119
+ def parsed_domain
120
+ @parsed_domain ||= begin
121
+ text = @text.dup
122
+ text = text.prepend('http://') unless text =~ %r{\Ahttps?://}
123
+ uri = Addressable::URI.parse(text)
122
124
  # properly parse http://foo edge cases
123
125
  # see https://github.com/sporkmonger/addressable/issues/145
124
- uri.host if uri.host =~ /\./
126
+ uri if uri.host.include?('.')
125
127
  end
126
128
  rescue Addressable::URI::InvalidURIError
127
129
  nil
@@ -1,3 +1,3 @@
1
1
  module NaughtyOrNice
2
- VERSION = "2.0.2"
2
+ VERSION = '2.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naughty_or_nice
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2016-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: public_suffix
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.9'
55
55
  - !ruby/object:Gem::Dependency
56
- name: shoulda
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.5'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.3'
75
+ version: '0.40'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.3'
82
+ version: '0.40'
83
83
  description: Naughty or Nice simplifies the process of extracting domain information
84
84
  from a domain-like string (an email, a URL, etc.) and checking whether it meets
85
85
  criteria you specify.
@@ -90,7 +90,6 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - LICENSE.md
92
92
  - README.md
93
- - Rakefile
94
93
  - lib/naughty_or_nice.rb
95
94
  - lib/naughty_or_nice/version.rb
96
95
  homepage: http://github.com/benbalter/naughty_or_nice
@@ -113,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
112
  version: '0'
114
113
  requirements: []
115
114
  rubyforge_project:
116
- rubygems_version: 2.4.8
115
+ rubygems_version: 2.6.7
117
116
  signing_key:
118
117
  specification_version: 4
119
118
  summary: You've made the list. We'll help you check it twice. Given a domain-like
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new(:test) do |test|
5
- test.libs << 'lib' << 'test'
6
- test.pattern = 'test/**/test_naughty_or_nice*.rb'
7
- test.verbose = true
8
- end
9
-
10
- desc "Open console with Naughty Or Nice loaded"
11
- task :console do
12
- exec "pry -r ./lib/naughty_or_nice.rb"
13
- end