public-suffix-list 0.2.1 → 0.2.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/Gemfile +6 -0
- data/README.rdoc +2 -1
- data/lib/public_suffix_list.rb +11 -8
- data/lib/public_suffix_list/cache_file.rb +9 -5
- data/lib/public_suffix_list/parser.rb +1 -0
- data/spec/caching_spec.rb +1 -0
- data/spec/cookie_calculation_spec.rb +1 -0
- data/spec/public_suffix_list_spec.rb +1 -0
- data/spec/rdoc_synopsis_spec.rb +1 -0
- data/spec/upcase_downcase_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41d03f21b529c0401313c948ee0117b05ae770e5774998697dcb53f623da1294
|
4
|
+
data.tar.gz: bc7f1cd08207f7a4c0bc17fc979ef46b02db4d663791c5b3601a8bb748785a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2bbf922fbae28c93ff74423f90b1da07f7578425c0e81ca2019e6757f79f31aafd7183b5b0764d93588293193ebb2dbddf7e8466f3264d13eb74e7017ec79a3
|
7
|
+
data.tar.gz: a9a106d7b6674dbbf83e39569669ce4d9897f4b4a7d9a4adf2b8bf39904c4fd5cc4427a8a9291d91307b2e49cbd9e2a7f52c2cf5335d9bc3f803cf3a7fb8af8f
|
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
= Public Suffix List
|
2
2
|
|
3
|
-
|
3
|
+
{<img src="https://travis-ci.org/toddsundsted/Public-Suffix-List.svg?branch=master">}[https://travis-ci.org/toddsundsted/Public-Suffix-List]
|
4
|
+
{<img src="https://img.shields.io/badge/docs-available-brightgreen.svg">}[https://toddsundsted.github.io/Public-Suffix-List/]
|
4
5
|
|
5
6
|
== Description
|
6
7
|
|
data/lib/public_suffix_list.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# typed: true
|
1
2
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
|
2
3
|
|
3
4
|
require 'open-uri'
|
@@ -6,7 +7,7 @@ require "public_suffix_list/parser.rb"
|
|
6
7
|
|
7
8
|
class PublicSuffixList
|
8
9
|
|
9
|
-
VERSION = "0.2.
|
10
|
+
VERSION = "0.2.2"
|
10
11
|
|
11
12
|
def self.config
|
12
13
|
@@config ||= Config.new
|
@@ -59,7 +60,7 @@ class PublicSuffixList
|
|
59
60
|
domain = domain.split(".")
|
60
61
|
result = best(match(domain, rules, true))
|
61
62
|
return ["", "", ""] if result.empty?
|
62
|
-
[gimme!(domain, result.size), gimme!(domain), domain].reverse.map { |d| d
|
63
|
+
[gimme!(domain, result.size), gimme!(domain), domain].reverse.map { |d| d.join(".") }
|
63
64
|
end
|
64
65
|
|
65
66
|
def tld(domain)
|
@@ -79,7 +80,10 @@ class PublicSuffixList
|
|
79
80
|
private
|
80
81
|
|
81
82
|
def fetch
|
82
|
-
@rules =
|
83
|
+
@rules =
|
84
|
+
if (file = open(@config.url))
|
85
|
+
Parser.parse(file)
|
86
|
+
end
|
83
87
|
end
|
84
88
|
|
85
89
|
def cache
|
@@ -95,7 +99,7 @@ class PublicSuffixList
|
|
95
99
|
domain = domain.dup
|
96
100
|
first = domain.pop
|
97
101
|
set = []
|
98
|
-
[[first
|
102
|
+
[[first&.downcase, first], ["!#{first&.downcase}", "!#{first}"], ["*", first]].each do |pattern, name|
|
99
103
|
if rules[pattern]
|
100
104
|
set << [name] if rules[pattern][:term]
|
101
105
|
match(domain, rules[pattern]).each { |result| set << [first] + result }
|
@@ -109,10 +113,9 @@ class PublicSuffixList
|
|
109
113
|
end
|
110
114
|
|
111
115
|
def best(results)
|
112
|
-
|
113
|
-
result =
|
114
|
-
result
|
115
|
-
result
|
116
|
+
result = results.find { |r| r.last&.[](0) == ?! } || results.sort { |a, b| a.size <=> b.size }.last
|
117
|
+
result = result[0..result.size - 2] if result && result.last&.[](0) == ?!
|
118
|
+
result || []
|
116
119
|
end
|
117
120
|
|
118
121
|
def gimme!(domain, n = 1)
|
@@ -1,21 +1,24 @@
|
|
1
|
+
# typed: true
|
1
2
|
class PublicSuffixList
|
2
3
|
|
3
4
|
class CacheFile
|
4
5
|
|
5
6
|
def initialize(config)
|
6
7
|
@config = config
|
8
|
+
@data = {}
|
7
9
|
end
|
8
10
|
|
9
11
|
def cache?
|
10
|
-
@config.cache_dir && File.directory?(@config.cache_dir) && true
|
12
|
+
@config.cache_dir && File.directory?(@config.cache_dir) && true || false
|
11
13
|
end
|
12
14
|
|
13
15
|
def file
|
14
|
-
|
16
|
+
path = URI.parse(@config.url)&.path&.split("/")&.last || ""
|
17
|
+
File.join(@config.cache_dir, path + ".cache")
|
15
18
|
end
|
16
19
|
|
17
20
|
def exist?
|
18
|
-
File.exist?(file)
|
21
|
+
cache? && File.exist?(file) && true || false
|
19
22
|
end
|
20
23
|
|
21
24
|
def delete
|
@@ -31,7 +34,8 @@ class PublicSuffixList
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def data
|
34
|
-
@data
|
37
|
+
@data.empty? and load_data
|
38
|
+
@data
|
35
39
|
end
|
36
40
|
|
37
41
|
def [](key)
|
@@ -39,7 +43,7 @@ class PublicSuffixList
|
|
39
43
|
end
|
40
44
|
|
41
45
|
def []=(key, value)
|
42
|
-
data.merge!({key => value, created_at: Time.now, tag: rand(
|
46
|
+
data.merge!({key => value, created_at: Time.now, tag: rand(2821109907456).to_s(36)}) and dump_data
|
43
47
|
end
|
44
48
|
|
45
49
|
def expired?
|
data/spec/caching_spec.rb
CHANGED
data/spec/rdoc_synopsis_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: public-suffix-list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Sundsted
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The Public Suffix List (http://publicsuffix.org/) is "a cross-vendor
|
14
14
|
initiative to provide an accurate list of domain name suffixes". Such a list is
|