rippersnapper 0.0.2 → 0.0.3

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: e4f4a7e8091b50527bdafa4c87972ede333f694f
4
- data.tar.gz: 91cdf3585d3d3801e247a1999109ff0a48f8e2b5
3
+ metadata.gz: f532fc959d773f20cf0542ec71061e82a3d32808
4
+ data.tar.gz: a092b51bae916693b046b012816316d69f390179
5
5
  SHA512:
6
- metadata.gz: b8cd9f500fef2b9aa50570f3a3e75933fc9995a5968f8a63c8b70fd7879c11ec39cd025f6e243e42e69d3dcfeb7a31b6201e99143d4b9fc1126337bec942c47c
7
- data.tar.gz: c56fa40791c55fbd0544fb9a518b63316c2322585c0f7f5367de931f1678cec6d638e161641e0275304238e565914df576f90ab3b944b8c699fdae54da804963
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rippersnapper
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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.2
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-12 00:00:00.000000000 Z
11
+ date: 2013-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler