naughty_or_nice 0.0.4 → 1.0.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: 9d85f51a7bb462630a5fa8145a88ebff5e51aed7
4
- data.tar.gz: 67c413c0373ed0dd8516c33f07c0852dca6e79a6
3
+ metadata.gz: 99393247edb23d92e4d1ddebb5a3a62b71c8179c
4
+ data.tar.gz: afc4922b88c3789f860fc95a8fcf26037d83bd7b
5
5
  SHA512:
6
- metadata.gz: d8a2b4b6a128bc0cbd5194281552941e17948f9db74e42081c26729b1d56d05cf61d1a3f55bc5de348868755e711361241df4f83d66634419522795ed9fa377d
7
- data.tar.gz: a19f454d60ca1406921622c01ce20b45cb292f567530e320a8317b1a6f66c1d64015e09380b2f3e30a52477bff14a28d3bf3894028fd24ae1a5f5c9e09f2f6dc
6
+ metadata.gz: e9c88f8fc3407466c321177f0a6074b797aba84dcb5be52f1b78e5a124e7ed51b21560ea03333e9a58cedd0f5bf2a79e7b8b55a9382d916cee854d171a7bb15e
7
+ data.tar.gz: 3f9cde45e96febf46407d91efa40c3e3484c01f337c781bc11f6720ee5482cefa041a4c5cbb6c22f184ba01a168b333b2cd0bc604fab5a8233c5aacdb0df3f12
data/README.md CHANGED
@@ -8,14 +8,16 @@ Naughty or Nice simplifies the process of extracting domain information from a d
8
8
 
9
9
  Naughty or Nice doesn't do too much on its own. Out of the box, it can extract a domain from a domain-like string, and can verify that it is, in fact, a valid domain. It does this by leveraging the power of [Addressable](https://github.com/sporkmonger/addressable), the [Public Suffix List](http://publicsuffix.org/), and the associated [Ruby Gem](https://github.com/weppos/publicsuffix-ruby).
10
10
 
11
- The true power of Naughty or Nice comes when you extended it into a child class.
11
+ The true power of Naughty or Nice comes when you include it into your own class.
12
12
 
13
- ## Extending Naughty or Nice
13
+ ## Implementing Naughty or Nice
14
14
 
15
15
  Let's say you have a list of three domains, `foo.com`, `bar.com`, and `foobar.com`. You'd spec out a class like so:
16
16
 
17
17
  ```ruby
18
- class Checker < NaughtyOrNice
18
+ class Checker
19
+
20
+ include NaughtyOrNice
19
21
  DOMAINS = %w[foo.com bar.com foobar.com]
20
22
 
21
23
  def valid?
@@ -26,9 +28,9 @@ end
26
28
 
27
29
  That's it! Just overwrite the `valid?` method and Naughty or Nice takes care of the rest.
28
30
 
29
- ## Using the extended class
31
+ ## Using the included methods
30
32
 
31
- There are a handful of magic methods that your child class automatically gets. You can throw any domain-like string at your new `Checker` class, and figure out if it's on the list. Here's a few examples:
33
+ There are a handful of magic methods that your class automatically gets. You can throw any domain-like string at your new `Checker` class, and figure out if it's on the list. Here's a few examples:
32
34
 
33
35
  ```ruby
34
36
  Checker.valid? "foo.com" #=> true
@@ -0,0 +1,3 @@
1
+ module NaughtyOrNice
2
+ VERSION = "1.0.0"
3
+ end
@@ -1,13 +1,8 @@
1
1
  require 'public_suffix'
2
2
  require "addressable/uri"
3
+ require_relative './naughty_or_nice/version'
3
4
 
4
- class NaughtyOrNice
5
-
6
- class << self
7
- def valid?(text)
8
- self.new(text).valid?
9
- end
10
- end
5
+ module NaughtyOrNice
11
6
 
12
7
  # Source: http://bit.ly/1n2X9iv
13
8
  EMAIL_REGEX = %r{
@@ -48,8 +43,24 @@ class NaughtyOrNice
48
43
  $
49
44
  }xi
50
45
 
51
- def initialize(text)
52
- @text = text.to_s.downcase.strip
46
+ module ClassMethods
47
+ def valid?(text)
48
+ self.new(text).valid?
49
+ end
50
+ end
51
+
52
+ # Ruby idiom that allows `include` to create class methods
53
+ def self.included(base)
54
+ base.extend(ClassMethods)
55
+ end
56
+
57
+ def initialize(domain)
58
+ if domain.is_a?(PublicSuffix::Domain)
59
+ @domain_parts = domain
60
+ @text = domain.to_s
61
+ else
62
+ @text = domain.to_s.downcase.strip
63
+ end
53
64
  end
54
65
 
55
66
  # Parse the domain from the input string
@@ -83,7 +94,7 @@ class NaughtyOrNice
83
94
  #
84
95
  # Returns boolean true if a valid domain, otherwise false
85
96
  def valid?
86
- PublicSuffix.valid?(domain)
97
+ !!(domain_parts && domain_parts.valid?)
87
98
  end
88
99
 
89
100
  # Is the input text in the form of a valid email address?
@@ -99,9 +110,11 @@ class NaughtyOrNice
99
110
  #
100
111
  # Returns the domain object or nil, but no errors, never an error
101
112
  def domain_parts
102
- PublicSuffix.parse domain
103
- rescue PublicSuffix::DomainInvalid
104
- nil
113
+ @domain_parts ||= begin
114
+ PublicSuffix.parse domain
115
+ rescue PublicSuffix::DomainInvalid, PublicSuffix::DomainNotAllowed
116
+ nil
117
+ end
105
118
  end
106
119
 
107
120
  def inspect
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naughty_or_nice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.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-06-19 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: public_suffix
@@ -92,6 +92,7 @@ files:
92
92
  - README.md
93
93
  - Rakefile
94
94
  - lib/naughty_or_nice.rb
95
+ - lib/naughty_or_nice/version.rb
95
96
  homepage: http://github.com/benbalter/naughty_or_nice
96
97
  licenses:
97
98
  - MIT