lazy_domain 0.0.1 → 0.0.2

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: 22211abf594c3ca41c920dedf2556c9c8181fb06
4
- data.tar.gz: 2bb691ae29b03dfb5c262c235f23c663c65b65c4
3
+ metadata.gz: 97145afd64c8587003306a7506d5714958209a15
4
+ data.tar.gz: e5d92e18ef835249af2329d42e3c9a95c3994846
5
5
  SHA512:
6
- metadata.gz: ff14b0436b383ca2266a878246e9b9ba43efe424b2e5a165ac0bd4c462436564254cc7f2c0a253c2056a1e87e80fc4986020ee7edfa52b61f4517fd157f1bf33
7
- data.tar.gz: 2212be8528f9e956ee427e393a00c8307d73baf3f4a52a3dc98c0359b548ac26bc586b5d0dff6af7a78f4bb913a487f7d70c963e4b3bd7590262f0cd13778d42
6
+ metadata.gz: 9919922fd5e9ced77cd7d9b286046ba3d52cc35f7770c56db39ebe91d34f6de049c120e01b78e32621aca6103af064c48b9a52e0c6a1ccc9a5f0368b40d93c1a
7
+ data.tar.gz: a203fa59508c2a15db7a459d91dca55a8a4acda2b8800d5ad7cacf5a3ed1c8993bd4c26c4f0c8fe1146708707efc6c9d0c838ff1a036dad50bf84b43b88c0c6c
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # LazyDomain
2
+ [![Build Status](https://travis-ci.org/m8ss/lazy_domain.svg?branch=master)](https://travis-ci.org/m8ss/lazy_domain) [![Code Climate](https://codeclimate.com/github/m8ss/lazy_domain/badges/gpa.svg)](https://codeclimate.com/github/m8ss/lazy_domain) [![Gem Version](https://badge.fury.io/rb/lazy_domain.svg)](https://badge.fury.io/rb/lazy_domain)
2
3
 
3
4
  Parse varying urls with [PublicSuffix](https://github.com/weppos/publicsuffix-ruby) the easy way.
4
5
 
@@ -10,10 +11,7 @@ LazyDomain assumes it could be either way and uses URI to make up the difference
10
11
 
11
12
  ## Installation
12
13
 
13
- ```
14
- gem install lazy_domain
15
-
16
- ```
14
+ $ gem install lazy_domain
17
15
 
18
16
  ## Usage
19
17
 
@@ -24,48 +22,48 @@ Because LazyDomain is simply a wrapper for [PublicSuffix](https://github.com/wep
24
22
  Example domain without subdomains.
25
23
 
26
24
  ```ruby
27
- domain = LazyDomain.parse("google.com")
28
- # => #<PublicSuffix::Domain>
29
- domain.tld
30
- # => "com"
31
- domain.sld
32
- # => "google"
33
- domain.trd
34
- # => nil
35
- domain.domain
36
- # => "google.com"
37
- domain.subdomain
38
- # => nil
25
+ domain = LazyDomain.parse("google.com")
26
+ # => #<PublicSuffix::Domain>
27
+ domain.tld
28
+ # => "com"
29
+ domain.sld
30
+ # => "google"
31
+ domain.trd
32
+ # => nil
33
+ domain.domain
34
+ # => "google.com"
35
+ domain.subdomain
36
+ # => nil
39
37
  ```
40
38
 
41
39
  Example domain with subdomains.
42
40
 
43
41
  ```ruby
44
- domain = LazyDomain.parse("www.google.com")
45
- # => #<PublicSuffix::Domain>
46
- domain.tld
47
- # => "com"
48
- domain.sld
49
- # => "google"
50
- domain.trd
51
- # => "www"
52
- domain.domain
53
- # => "google.com"
54
- domain.subdomain
55
- # => "www.google.com"
42
+ domain = LazyDomain.parse("www.google.com")
43
+ # => #<PublicSuffix::Domain>
44
+ domain.tld
45
+ # => "com"
46
+ domain.sld
47
+ # => "google"
48
+ domain.trd
49
+ # => "www"
50
+ domain.domain
51
+ # => "google.com"
52
+ domain.subdomain
53
+ # => "www.google.com"
56
54
  ```
57
55
 
58
56
  Simple validation example.
59
57
 
60
58
  ```ruby
61
- LazyDomain.valid?("google.com")
62
- # => true
59
+ LazyDomain.valid?("google.com")
60
+ # => true
63
61
 
64
- LazyDomain.valid?("www.google.com")
65
- # => true
62
+ LazyDomain.valid?("www.google.com")
63
+ # => true
66
64
 
67
- LazyDomain.valid?("x.yz")
68
- # => false
65
+ LazyDomain.valid?("x.yz")
66
+ # => false
69
67
  ```
70
68
 
71
69
  ## Advanced Usage
@@ -75,26 +73,26 @@ You can do everything mentioned above, but the magic of LazyDomain is you can no
75
73
  For example, all of this...
76
74
 
77
75
  ```ruby
78
- domain = LazyDomain.parse("google.com")
76
+ domain = LazyDomain.parse("google.com")
79
77
 
80
- domain = LazyDomain.parse("http://google.com")
78
+ domain = LazyDomain.parse("http://google.com")
81
79
 
82
- domain = LazyDomain.parse("ftp://google.com")
80
+ domain = LazyDomain.parse("ftp://google.com")
83
81
 
84
- domain = LazyDomain.parse("somethingcrazy://google.com")
82
+ domain = LazyDomain.parse("somethingcrazy://google.com")
85
83
 
86
- domain = LazyDomain.parse("http://abc.defg.hijk.google.com")
84
+ domain = LazyDomain.parse("http://abc.defg.hijk.google.com")
87
85
 
88
- domain = LazyDomain.parse("http://abc.defg.hijk.google.com/asubdirectory/andanother")
86
+ domain = LazyDomain.parse("http://abc.defg.hijk.google.com/asubdirectory/andanother")
89
87
 
90
88
  ```
91
89
 
92
90
  ...returns something like this.
93
91
 
94
- ```ruby
95
92
 
96
- => #<PublicSuffix::Domain:0x0055c2344f0168 @sld="google", @tld="com", @trd="abc.defg.hijk">
93
+ ```ruby
97
94
 
95
+ # => #<PublicSuffix::Domain:0x0055c2344f0168 @sld="google", @tld="com", @trd="abc.defg.hijk">
98
96
 
99
97
  ```
100
98
 
data/Rakefile CHANGED
@@ -1,5 +1,12 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_lazy_domain*.rb'
8
+ test.verbose = true
9
+ end
3
10
 
4
11
  desc 'Open console with lazy_domain loaded'
5
12
  task :console do
data/lib/lazy_domain.rb CHANGED
@@ -6,17 +6,33 @@ module AutoHTTP
6
6
  # Looks for any character before '://'
7
7
  TP_REGEX = %r{[\w]+(\b:\/\/)}
8
8
 
9
+ # Looks if there is are non word characters before domain but no letters.
10
+ # Example is '://google.com' or '#$/google.com', etc.
11
+ BADURL_REGEX = /\A(\W+)/
12
+
9
13
  # Returns true if there is any character before '://'' in a url.
10
14
  # ie. 'something://google.com' or 'xyz://google.com'
11
15
  #
12
16
  # Returns false if somehting like '://google.com' or 'google.com'.
13
- def hastp(str)
17
+ def hastp?(str)
14
18
  !(str =~ TP_REGEX).nil?
15
19
  end
16
20
 
21
+ # Boolean, returns true if anything besides '*://' is given
22
+ def bad_protocol?(str)
23
+ !(str =~ BADURL_REGEX).nil?
24
+ end
25
+
26
+ # Strip out the bad characters.
27
+ # If there is nothing bad to strip, returns the original string.
28
+ def strip_bad(str)
29
+ str.gsub!(BADURL_REGEX, '') || str
30
+ end
31
+
17
32
  # Add 'http://' if something is not already present.
18
33
  def autohttp(str)
19
- str.prepend('http://') unless hastp(str)
34
+ strip_bad(str) if bad_protocol?(str)
35
+ str.prepend('http://') unless hastp?(str)
20
36
  str
21
37
  end
22
38
  end
@@ -1,3 +1,3 @@
1
1
  module LazyDomain
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mason
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-10 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: public_suffix
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: shoulda
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.3'
33
+ version: '3.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.3'
40
+ version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement