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 +4 -4
- data/README.md +1 -1
- data/lib/naughty_or_nice.rb +21 -19
- data/lib/naughty_or_nice/version.rb +1 -1
- metadata +11 -12
- data/Rakefile +0 -13
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c1f0a6ca903c8a3019b9e566099f6454b1d2b941
         | 
| 4 | 
            +
              data.tar.gz: daf9330f225766d7d2bdedee264d6d98a8bcc39f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2e0f1f7f05521e3c08f124f28513e3f8a19c752d84dc96288793a48f58aaa8493876cda29d34a31c1e3acbe3a4c0284a9f77689aa116f880335262a32ae96ba6
         | 
| 7 | 
            +
              data.tar.gz: bc06c3ed9f60e07525e016f80bb7ff23f15f0307712b06d6b6142a873311a043e1792b9bc63d7fa66e365569d4f58f88e941daf3d0475da8e054e190fba34f00
         | 
    
        data/README.md
    CHANGED
    
    
    
        data/lib/naughty_or_nice.rb
    CHANGED
    
    | @@ -1,9 +1,9 @@ | |
| 1 1 | 
             
            require 'public_suffix'
         | 
| 2 | 
            -
            require  | 
| 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 | 
            -
                   | 
| 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( | 
| 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 | 
            -
                 | 
| 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 | 
            -
                 | 
| 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  | 
| 112 | 
            -
                 | 
| 113 | 
            -
             | 
| 114 | 
            -
                 | 
| 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 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
                   | 
| 120 | 
            -
             | 
| 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 | 
| 126 | 
            +
                  uri if uri.host.include?('.')
         | 
| 125 127 | 
             
                end
         | 
| 126 128 | 
             
              rescue Addressable::URI::InvalidURIError
         | 
| 127 129 | 
             
                nil
         | 
    
        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 | 
| 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:  | 
| 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: ' | 
| 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: ' | 
| 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:  | 
| 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:  | 
| 70 | 
            +
              name: rubocop
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 72 | 
             
                requirements:
         | 
| 73 73 | 
             
                - - "~>"
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            -
                    version: ' | 
| 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: ' | 
| 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. | 
| 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
         |