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 +4 -4
- data/README.md +40 -42
- data/Rakefile +7 -0
- data/lib/lazy_domain.rb +18 -2
- data/lib/lazy_domain/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97145afd64c8587003306a7506d5714958209a15
|
4
|
+
data.tar.gz: e5d92e18ef835249af2329d42e3c9a95c3994846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9919922fd5e9ced77cd7d9b286046ba3d52cc35f7770c56db39ebe91d34f6de049c120e01b78e32621aca6103af064c48b9a52e0c6a1ccc9a5f0368b40d93c1a
|
7
|
+
data.tar.gz: a203fa59508c2a15db7a459d91dca55a8a4acda2b8800d5ad7cacf5a3ed1c8993bd4c26c4f0c8fe1146708707efc6c9d0c838ff1a036dad50bf84b43b88c0c6c
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# LazyDomain
|
2
|
+
[](https://travis-ci.org/m8ss/lazy_domain) [](https://codeclimate.com/github/m8ss/lazy_domain) [](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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
62
|
-
|
59
|
+
LazyDomain.valid?("google.com")
|
60
|
+
# => true
|
63
61
|
|
64
|
-
|
65
|
-
|
62
|
+
LazyDomain.valid?("www.google.com")
|
63
|
+
# => true
|
66
64
|
|
67
|
-
|
68
|
-
|
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
|
-
|
76
|
+
domain = LazyDomain.parse("google.com")
|
79
77
|
|
80
|
-
|
78
|
+
domain = LazyDomain.parse("http://google.com")
|
81
79
|
|
82
|
-
|
80
|
+
domain = LazyDomain.parse("ftp://google.com")
|
83
81
|
|
84
|
-
|
82
|
+
domain = LazyDomain.parse("somethingcrazy://google.com")
|
85
83
|
|
86
|
-
|
84
|
+
domain = LazyDomain.parse("http://abc.defg.hijk.google.com")
|
87
85
|
|
88
|
-
|
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
|
-
|
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
|
34
|
+
strip_bad(str) if bad_protocol?(str)
|
35
|
+
str.prepend('http://') unless hastp?(str)
|
20
36
|
str
|
21
37
|
end
|
22
38
|
end
|
data/lib/lazy_domain/version.rb
CHANGED
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.
|
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-
|
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:
|
28
|
+
name: shoulda
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '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.
|
40
|
+
version: '3.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|