rippersnapper 0.0.6 → 0.0.7

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.
@@ -1,18 +1,23 @@
1
1
  module Rippersnapper
2
-
3
- ###
4
- # Single Responsibility:
5
- # Finds a suffix match in a list of suffixes
6
-
7
2
  class SuffixFileReader
8
3
  attr_reader :file
9
4
 
5
+ # Reads in the public_suffix and populates public_suffixes for use in
6
+ # #contains
7
+ #
8
+ # @params file [File] file object containing public suffixes
9
+ # @return [self]
10
10
  def initialize file = nil
11
11
  @file = file || File.open(File.dirname(__FILE__) + "/public_suffix.dat", 'r')
12
12
  @public_suffixes = Hash.new { false }
13
13
  parse_file
14
14
  end
15
15
 
16
+ # Used to determin if a given suffix is present in the public_suffix data
17
+ # file
18
+ # @param suffix [String] the suffix which will be checked against the
19
+ # public_suffix file @return [Boolean] true or false depending on inclusion
20
+ # in suffix file
16
21
  def contains? suffix
17
22
  @public_suffixes[suffix] || begin
18
23
  suffix_parts = suffix.split('.')
@@ -24,8 +29,9 @@ module Rippersnapper
24
29
 
25
30
  private
26
31
 
27
- # NOTE: This could be extracted into an object if something more robust is
28
- # needed in the future
32
+ # Populates the @public_suffixes instance var. Each line is set to a key
33
+ # within the variable unless it starts with a // (slash slash)
34
+ # @return [void]
29
35
  def parse_file
30
36
  file.each_line do |line|
31
37
  line = line.strip
@@ -3,44 +3,80 @@ require 'uri'
3
3
  module Rippersnapper
4
4
  class Url
5
5
 
6
+ # @params url [String] The URL to be parsed
6
7
  def initialize url
7
8
  @url = url.to_s
8
9
  end
9
10
 
11
+ # URI object from url passed to initialize
12
+ # @return [URI] the URI object
13
+ # @example
14
+ # uri = Rippersnapper::Url.new("www.google.com?q=blah")
15
+ # uri.scheme #=> "https"
16
+ # uri.host #=> "www.google.com"
17
+ # uri.path #=> "/"
18
+ # uri.query #=> "q=blah"
10
19
  def uri
11
20
  @uri ||= URI.parse url
12
21
  end
13
22
 
23
+ # If url has a scheme use it if not assume http
24
+ # @return [String] The url to be processed
14
25
  def url
15
26
  return @url if @url =~ /:\/\// || @url.empty?
27
+
28
+ # sensible default
16
29
  "http://#{@url}"
17
30
  end
18
31
 
32
+ # Pass through to DomainParser object
33
+ # {Rippersnapper::DomainParser#suffix} see here for more details
19
34
  def suffix
20
35
  parsed_domain.suffix
21
36
  end
22
37
 
38
+ # Pass through to DomainParser object
39
+ # {Rippersnapper::DomainParser#domain} see here for more details
23
40
  def domain
24
41
  parsed_domain.domain
25
42
  end
26
43
 
44
+ # Pass through to DomainParser object
45
+ # {Rippersnapper::DomainParser#subdomain} see here for more details
27
46
  def subdomain
28
47
  parsed_domain.subdomain
29
48
  end
30
49
 
50
+ # convenience method to access URI scheme
51
+ # @example
52
+ # Rippersnapper::Url.new("https://www.google.com").scheme #=> "https"
53
+ # See {Rippersnapper::Url#uri} for more information
54
+ # @return [String]
31
55
  def scheme
32
56
  uri.scheme || ""
33
57
  end
34
58
 
59
+ # convenience method to access URI host
60
+ # @example
61
+ # Rippersnapper::Url.new("https://www.google.com").host #=> "google"
62
+ # See {Rippersnapper::Url#uri} for more information
63
+ # @return [String]
35
64
  def host
36
65
  uri.host || ""
37
66
  end
38
67
 
68
+ # construct path from uri query and uri path
69
+ # @return [String]
39
70
  def path
40
71
  return "#{uri.path}?#{uri.query}" if uri.query
41
72
  uri.path
42
73
  end
43
74
 
75
+ # convenience method to access URI port
76
+ # @example
77
+ # Rippersnapper::Url.new("https://www.google.com").port #=> 443
78
+ # See {Rippersnapper::Url#uri} for more information
79
+ # @return [String]
44
80
  def port
45
81
  uri.port
46
82
  end
@@ -1,3 +1,3 @@
1
1
  module Rippersnapper
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -45,7 +45,7 @@ module Rippersnapper
45
45
 
46
46
  context "rejecting invalid data" do
47
47
  it "doesn't match suffix that is not in file" do
48
- expect(subject.contains?("foo")).to be_false
48
+ expect(subject.contains?("baz")).to be_false
49
49
  end
50
50
 
51
51
  it "doesn't match complex suffix that are not in file" do
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rippersnapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Woods
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
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
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.13.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.13.0
55
55
  description: Rip and snap domains using Rippersnappers jaws of steele!
@@ -59,8 +59,8 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .rspec
62
+ - ".gitignore"
63
+ - ".rspec"
64
64
  - Gemfile
65
65
  - LICENSE.txt
66
66
  - README.md
@@ -88,17 +88,17 @@ require_paths:
88
88
  - lib
89
89
  required_ruby_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - '>='
91
+ - - ">="
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.1.11
101
+ rubygems_version: 2.2.2
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Named after the worst decepticon ever, a shark with T-Rex arms...