Class: PublicSuffixList
- Inherits:
-
Object
show all
- Defined in:
- lib/public_suffix_list.rb,
lib/public_suffix_list/parser.rb,
lib/public_suffix_list/cache_file.rb
Defined Under Namespace
Modules: Parser
Classes: CacheFile, Config
Constant Summary
collapse
- VERSION =
"0.1.4"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PublicSuffixList.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/public_suffix_list.rb', line 39
def initialize(options = {})
@config = self.class.config.dup
options.each { |k, v| @config.send("#{k}=", v) }
if @config.cache_dir
@cache_file = CacheFile.new(@config)
end
if @cache_file and @cache_file.exist?
uncache or (fetch and cache)
elsif @cache_file
fetch and cache
else
fetch
end
end
|
Instance Attribute Details
#cache_file ⇒ Object
Returns the value of attribute cache_file.
37
38
39
|
# File 'lib/public_suffix_list.rb', line 37
def cache_file
@cache_file
end
|
#config ⇒ Object
Returns the value of attribute config.
37
38
39
|
# File 'lib/public_suffix_list.rb', line 37
def config
@config
end
|
Class Method Details
.config ⇒ Object
11
12
13
|
# File 'lib/public_suffix_list.rb', line 11
def self.config
@@config ||= Config.new
end
|
15
16
17
|
# File 'lib/public_suffix_list.rb', line 15
def self.configure(&block)
yield config
end
|
Instance Method Details
#cdn(domain) ⇒ Object
70
71
72
73
74
|
# File 'lib/public_suffix_list.rb', line 70
def cdn(domain)
domain = domain.split(".")
result = best(match(domain, rules))
gimme!(domain, result.size + 1).join(".")
end
|
#rules ⇒ Object
54
55
56
|
# File 'lib/public_suffix_list.rb', line 54
def rules
@rules
end
|
#split(domain) ⇒ Object
58
59
60
61
62
|
# File 'lib/public_suffix_list.rb', line 58
def split(domain)
domain = domain.split(".")
result = best(match(domain, rules))
[gimme!(domain, result.size), gimme!(domain), domain].reverse.map { |d| d ? d.join(".") : "" }
end
|
#tld(domain) ⇒ Object
64
65
66
67
68
|
# File 'lib/public_suffix_list.rb', line 64
def tld(domain)
domain = domain.split(".")
result = best(match(domain, rules))
gimme!(domain, result.size).join(".")
end
|