rippersnapper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rippersnapper/domain_parser.rb +2 -3
- data/lib/rippersnapper/suffix_file_reader.rb +2 -4
- data/lib/rippersnapper/url.rb +4 -5
- data/lib/rippersnapper/version.rb +1 -1
- data/spec/rippersnapper/domain_parser_spec.rb +8 -0
- data/spec/rippersnapper/url_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f532fc959d773f20cf0542ec71061e82a3d32808
|
4
|
+
data.tar.gz: a092b51bae916693b046b012816316d69f390179
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49eaf5932ee7b4611f78c4083201bf7007984726445e5dbe7d37f26c84feb2156a1105924f59887bbc94c861c39d8de766e7eb16e27b2a2e8470c445302cbea5
|
7
|
+
data.tar.gz: 7df9d142edf0e98bae8d3db17045f2771d5a3510971937be8cf42d01a2824353f6e9ead1a701edc4e4769f5c3167a2d469572da3dc348263fda23c03c2acf3a7
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Rippersnapper
|
2
2
|
class DomainParser
|
3
|
-
attr_reader :domain, :subdomain
|
4
3
|
|
5
4
|
def initialize url
|
6
5
|
@url = url
|
@@ -13,14 +12,14 @@ module Rippersnapper
|
|
13
12
|
test = url_parts.last(iteration + 1).join(".")
|
14
13
|
found = test if suffix_exists?(test)
|
15
14
|
end
|
16
|
-
found
|
15
|
+
found.to_s
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
19
|
def domain
|
21
20
|
@domain ||= begin
|
22
21
|
remaining = url_parts - suffix_parts
|
23
|
-
remaining.last
|
22
|
+
remaining.last.to_s
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -9,8 +9,6 @@ module Rippersnapper
|
|
9
9
|
|
10
10
|
def initialize file = nil
|
11
11
|
@file = file || File.open(File.dirname(__FILE__) + "/public_suffix.dat", 'r')
|
12
|
-
# Recursive hash of hashes http://stackoverflow.com/a/170240/973860
|
13
|
-
#@public_suffixes = Hash.new(&(p=lambda{|h,k| h[k] = Hash.new(&p)}))
|
14
12
|
@public_suffixes = Hash.new { false }
|
15
13
|
parse_file
|
16
14
|
end
|
@@ -26,6 +24,8 @@ module Rippersnapper
|
|
26
24
|
|
27
25
|
private
|
28
26
|
|
27
|
+
# NOTE: This could be extracted into an object if something more robust is
|
28
|
+
# needed in the future
|
29
29
|
def parse_file
|
30
30
|
file.each_line do |line|
|
31
31
|
line = line.strip
|
@@ -34,7 +34,5 @@ module Rippersnapper
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
data/lib/rippersnapper/url.rb
CHANGED
@@ -2,10 +2,9 @@ require 'URI'
|
|
2
2
|
|
3
3
|
module Rippersnapper
|
4
4
|
class Url
|
5
|
-
attr_accessor :subdomain, :domain
|
6
5
|
|
7
6
|
def initialize url
|
8
|
-
@url = url
|
7
|
+
@url = url.to_s
|
9
8
|
end
|
10
9
|
|
11
10
|
def uri
|
@@ -13,7 +12,7 @@ module Rippersnapper
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def url
|
16
|
-
return @url if @url =~ /:\/\//
|
15
|
+
return @url if @url =~ /:\/\// || @url.empty?
|
17
16
|
"http://#{@url}"
|
18
17
|
end
|
19
18
|
|
@@ -30,11 +29,11 @@ module Rippersnapper
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def scheme
|
33
|
-
uri.scheme
|
32
|
+
uri.scheme || ""
|
34
33
|
end
|
35
34
|
|
36
35
|
def host
|
37
|
-
uri.host
|
36
|
+
uri.host || ""
|
38
37
|
end
|
39
38
|
|
40
39
|
def path
|
@@ -17,5 +17,13 @@ module Rippersnapper
|
|
17
17
|
its(:domain) { should eq "google" }
|
18
18
|
its(:suffix) { should eq "whatever.sapporo.jp" }
|
19
19
|
end
|
20
|
+
|
21
|
+
context "empty url" do
|
22
|
+
subject { DomainParser.new "" }
|
23
|
+
its(:subdomain) { should eq "" }
|
24
|
+
its(:domain) { should eq "" }
|
25
|
+
its(:suffix) { should eq "" }
|
26
|
+
end
|
27
|
+
|
20
28
|
end
|
21
29
|
end
|
@@ -42,5 +42,16 @@ module Rippersnapper
|
|
42
42
|
its(:suffix) { should eq "com" }
|
43
43
|
its(:domain) { should eq "google" }
|
44
44
|
end
|
45
|
+
|
46
|
+
context "when url is nil" do
|
47
|
+
subject {Url.new nil}
|
48
|
+
its(:url) { should eq "" }
|
49
|
+
its(:path) { should eq "" }
|
50
|
+
its(:scheme) { should eq "" }
|
51
|
+
its(:host) { should eq "" }
|
52
|
+
its(:suffix) { should eq "" }
|
53
|
+
its(:domain) { should eq "" }
|
54
|
+
its(:subdomain) { should eq "" }
|
55
|
+
end
|
45
56
|
end
|
46
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rippersnapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Woods
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|