ryodo 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rbenv-gemsets +1 -0
- data/.rbenv-version +1 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +46 -0
- data/LICENSE.txt +20 -0
- data/README.md +72 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/checks/matching.rb +89 -0
- data/data/suffix.dat +4317 -0
- data/lib/ryodo/convenience/.u.rb +19 -0
- data/lib/ryodo/convenience.rb +13 -0
- data/lib/ryodo/domain.rb +83 -0
- data/lib/ryodo/ext/string.rb +9 -0
- data/lib/ryodo/methods.rb +12 -0
- data/lib/ryodo/parser.rb +37 -0
- data/lib/ryodo/rule.rb +15 -0
- data/lib/ryodo/rule_set.rb +77 -0
- data/lib/ryodo/suffix_list.rb +57 -0
- data/lib/ryodo/suffix_list_fetcher.rb +54 -0
- data/lib/ryodo.rb +29 -0
- data/spec/_files/mozilla_effective_tld_names.dat +5229 -0
- data/spec/ryodo/suffix_list_fetcher_spec.rb +81 -0
- data/spec/ryodo/suffix_list_spec.rb +50 -0
- data/spec/ryodo_spec.rb +6 -0
- data/spec/spec_helper.rb +37 -0
- metadata +192 -0
data/.document
ADDED
data/.rbenv-gemsets
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ryodo
|
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p194
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3@ryodo
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.0.6)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
fakeweb (1.3.0)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.8.3)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rdoc
|
13
|
+
json (1.7.3)
|
14
|
+
method_source (0.7.1)
|
15
|
+
pry (0.9.9.6)
|
16
|
+
coderay (~> 1.0.5)
|
17
|
+
method_source (~> 0.7.1)
|
18
|
+
slop (>= 2.4.4, < 3)
|
19
|
+
pry-doc (0.4.2)
|
20
|
+
pry (>= 0.9.0)
|
21
|
+
yard (~> 0.8.1)
|
22
|
+
rake (0.9.2.2)
|
23
|
+
rdoc (3.12)
|
24
|
+
json (~> 1.4)
|
25
|
+
rspec (2.10.0)
|
26
|
+
rspec-core (~> 2.10.0)
|
27
|
+
rspec-expectations (~> 2.10.0)
|
28
|
+
rspec-mocks (~> 2.10.0)
|
29
|
+
rspec-core (2.10.1)
|
30
|
+
rspec-expectations (2.10.0)
|
31
|
+
diff-lcs (~> 1.1.3)
|
32
|
+
rspec-mocks (2.10.1)
|
33
|
+
slop (2.4.4)
|
34
|
+
yard (0.8.1)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler
|
41
|
+
fakeweb
|
42
|
+
jeweler
|
43
|
+
pry
|
44
|
+
pry-doc
|
45
|
+
rake
|
46
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Christoph Grabo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# ryodo [![](https://secure.travis-ci.org/asaaki/ryodo.png)](http://travis-ci.org/asaaki/ryodo)
|
2
|
+
|
3
|
+
**ryōdo【領土】 りょうど — A domain name parser**
|
4
|
+
|
5
|
+
----
|
6
|
+
|
7
|
+
This is a pure Ruby implementation of the [regdomr](https://github.com/asaaki/regdomr) gem, but with slightly different API.
|
8
|
+
|
9
|
+
Without the Cext backend it should be also easily usable with Ruby implemenations like JRuby.
|
10
|
+
|
11
|
+
**Works only with Ruby 1.9.x!**
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
dom = Ryodo.parse("my.awesome.domain.co.jp")
|
17
|
+
#=> Ryodo::Domain
|
18
|
+
|
19
|
+
# SUBDOMAIN DOMAIN TLD
|
20
|
+
dom.tld #=> "co.jp" - returns only the public suffix
|
21
|
+
dom.domain #=> "domain.co.jp" - returns only registered/registrable domain
|
22
|
+
dom.subdomain #=> "my.awesome" - returns only subdomain parts
|
23
|
+
dom #=> "my.awesome.domain.co.jp" - returns full domain string
|
24
|
+
dom.fqdn #=> "my.awesome.domain.co.jp." - full domain + trailing dot
|
25
|
+
|
26
|
+
# all parts also reversable
|
27
|
+
# mostly used on domain/FQDN
|
28
|
+
dom.reverse #=> "my.awesome.domain.co.jp"
|
29
|
+
dom.fqdn.reverse #=> ".jp.co.domain.awesome.my"
|
30
|
+
|
31
|
+
dom.to_a #=> ["my","awesome","domain","co","jp"]
|
32
|
+
dom.domain.to_a #=> ["domain","co","jp"]
|
33
|
+
dom.subdomain.to_a #=> ["my","awesome"]
|
34
|
+
dom.fqdn.to_a #=> ["my","awesome","domain","co","jp",""]
|
35
|
+
|
36
|
+
# .to_a also usable with parameter :reverse (or shorthand :r)
|
37
|
+
dom.domain.to_a(:reverse) #=> ["jp","co","domain","awesome","my"]
|
38
|
+
dom.fqdn.to_a(:reverse) #=> ["","jp","co","domain","awesome","my"]
|
39
|
+
dom.fqdn.to_a(:r) #=> ["","jp","co","domain","awesome","my"]
|
40
|
+
```
|
41
|
+
|
42
|
+
You can call it in different ways:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Ryodo.parse("my.awesome.domain.co.jp")
|
46
|
+
Ryodo("my.awesome.domain.co.jp")
|
47
|
+
Ryodo["my.awesome.domain.co.jp"]
|
48
|
+
ryodo("my.awesome.domain.co.jp")
|
49
|
+
|
50
|
+
# String extension
|
51
|
+
"my.awesome.domain.co.jp".to_domain
|
52
|
+
"my.awesome.domain.co.jp".ryodo
|
53
|
+
```
|
54
|
+
|
55
|
+
UTF-8 junkie? ;o)
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
# encoding: utf-8
|
59
|
+
ryōdo("my.awesome.domain.co.jp")
|
60
|
+
領土("my.awesome.domain.co.jp")
|
61
|
+
りょうど("my.awesome.domain.co.jp")
|
62
|
+
```
|
63
|
+
|
64
|
+
## Foo …
|
65
|
+
|
66
|
+
"Uh, excuse me Sir … just one more question." — Columbo (Peter Falk †)
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
MIT/X11 — see `LICENSE.txt`
|
71
|
+
|
72
|
+
(c) 2012 Christoph Grabo
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require "rake"
|
13
|
+
require "jeweler"
|
14
|
+
require "rspec"
|
15
|
+
require "rspec/core/rake_task"
|
16
|
+
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
19
|
+
gem.name = "ryodo"
|
20
|
+
gem.homepage = "http://github.com/asaaki/ryodo"
|
21
|
+
gem.license = "MIT"
|
22
|
+
gem.summary = %Q{ryōdo【領土】 りょうど — A domain name parser}
|
23
|
+
gem.description = %Q{ryōdo【領土】 りょうど — A domain name parser gem}
|
24
|
+
gem.email = "chris@dinarrr.com"
|
25
|
+
gem.authors = ["Christoph Grabo"]
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
desc "Starts IRB with gem loaded"
|
31
|
+
task :irb do
|
32
|
+
sh "irb -I lib -r ryodo"
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Starts PRY with gem loaded"
|
36
|
+
task :pry do
|
37
|
+
sh "pry -I lib -r ryodo --no-pager"
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Starts PRY with gem loaded (RYODO_NO_U)"
|
41
|
+
task :pryu do
|
42
|
+
sh "pry -I lib --no-pager -e 'RYODO_NO_U=true;require \"ryodo\"'"
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Run all specs"
|
46
|
+
task RSpec::Core::RakeTask.new(:spec) do |t|
|
47
|
+
t.pattern = 'spec/**/*_spec.rb'
|
48
|
+
t.verbose = false
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Fetch and save public suffix data (task for updates)"
|
52
|
+
task :fetch_data do
|
53
|
+
require "ryodo"
|
54
|
+
Ryodo::SuffixListFetcher.fetch_and_save!
|
55
|
+
end
|
56
|
+
|
57
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/checks/matching.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
$: << "lib"
|
4
|
+
require "ryodo"
|
5
|
+
|
6
|
+
def checkPublicSuffix query, expectation
|
7
|
+
|
8
|
+
q = Ryodo[query]
|
9
|
+
calculated = q.domain.nil? ? "NULL" : q.domain
|
10
|
+
passed = (calculated==expectation) ? " OK" : "FAIL"
|
11
|
+
|
12
|
+
puts "#{passed} === Q: #{query.ljust(20)} | #{expectation.rjust(20)} <=> #{calculated.ljust(20)}"
|
13
|
+
end
|
14
|
+
|
15
|
+
# NULL input.
|
16
|
+
checkPublicSuffix('NULL', 'NULL')
|
17
|
+
# Mixed case.
|
18
|
+
checkPublicSuffix('COM', 'NULL')
|
19
|
+
checkPublicSuffix('example.COM', 'example.com')
|
20
|
+
checkPublicSuffix('WwW.example.COM', 'example.com')
|
21
|
+
# Leading dot.
|
22
|
+
checkPublicSuffix('.com', 'NULL')
|
23
|
+
checkPublicSuffix('.example', 'NULL')
|
24
|
+
checkPublicSuffix('.example.com', 'NULL')
|
25
|
+
checkPublicSuffix('.example.example', 'NULL')
|
26
|
+
# Leading dot for reversed FQDN
|
27
|
+
checkPublicSuffix('.com.example', 'example.com')
|
28
|
+
# Unlisted TLD.
|
29
|
+
checkPublicSuffix('example', 'NULL')
|
30
|
+
checkPublicSuffix('example.example', 'NULL')
|
31
|
+
checkPublicSuffix('b.example.example', 'NULL')
|
32
|
+
checkPublicSuffix('a.b.example.example', 'NULL')
|
33
|
+
# Listed, but non-Internet, TLD.
|
34
|
+
checkPublicSuffix('local', 'NULL')
|
35
|
+
checkPublicSuffix('example.local', 'NULL')
|
36
|
+
checkPublicSuffix('b.example.local', 'NULL')
|
37
|
+
checkPublicSuffix('a.b.example.local', 'NULL')
|
38
|
+
# TLD with only 1 rule.
|
39
|
+
checkPublicSuffix('biz', 'NULL')
|
40
|
+
checkPublicSuffix('domain.biz', 'domain.biz')
|
41
|
+
checkPublicSuffix('b.domain.biz', 'domain.biz')
|
42
|
+
checkPublicSuffix('a.b.domain.biz', 'domain.biz')
|
43
|
+
# TLD with some 2-level rules.
|
44
|
+
checkPublicSuffix('com', 'NULL')
|
45
|
+
checkPublicSuffix('example.com', 'example.com')
|
46
|
+
checkPublicSuffix('b.example.com', 'example.com')
|
47
|
+
checkPublicSuffix('a.b.example.com', 'example.com')
|
48
|
+
checkPublicSuffix('uk.com', 'NULL')
|
49
|
+
checkPublicSuffix('example.uk.com', 'example.uk.com')
|
50
|
+
checkPublicSuffix('b.example.uk.com', 'example.uk.com')
|
51
|
+
checkPublicSuffix('a.b.example.uk.com', 'example.uk.com')
|
52
|
+
checkPublicSuffix('test.ac', 'test.ac')
|
53
|
+
# TLD with only 1 (wildcard) rule.
|
54
|
+
checkPublicSuffix('cy', 'NULL')
|
55
|
+
checkPublicSuffix('c.cy', 'NULL')
|
56
|
+
checkPublicSuffix('b.c.cy', 'b.c.cy')
|
57
|
+
checkPublicSuffix('a.b.c.cy', 'b.c.cy')
|
58
|
+
# More complex TLD.
|
59
|
+
checkPublicSuffix('jp', 'NULL')
|
60
|
+
checkPublicSuffix('test.jp', 'test.jp')
|
61
|
+
checkPublicSuffix('www.test.jp', 'test.jp')
|
62
|
+
checkPublicSuffix('ac.jp', 'NULL')
|
63
|
+
checkPublicSuffix('test.ac.jp', 'test.ac.jp')
|
64
|
+
checkPublicSuffix('www.test.ac.jp', 'test.ac.jp')
|
65
|
+
checkPublicSuffix('kyoto.jp', 'NULL')
|
66
|
+
checkPublicSuffix('c.kyoto.jp', 'NULL')
|
67
|
+
checkPublicSuffix('b.c.kyoto.jp', 'b.c.kyoto.jp')
|
68
|
+
checkPublicSuffix('a.b.c.kyoto.jp', 'b.c.kyoto.jp')
|
69
|
+
checkPublicSuffix('pref.kyoto.jp', 'pref.kyoto.jp') # Exception rule.
|
70
|
+
checkPublicSuffix('www.pref.kyoto.jp', 'pref.kyoto.jp') # Exception rule.
|
71
|
+
checkPublicSuffix('city.kyoto.jp', 'city.kyoto.jp') # Exception rule.
|
72
|
+
checkPublicSuffix('www.city.kyoto.jp', 'city.kyoto.jp') # Exception rule.
|
73
|
+
# TLD with a wildcard rule and exceptions.
|
74
|
+
checkPublicSuffix('om', 'NULL')
|
75
|
+
checkPublicSuffix('test.om', 'NULL')
|
76
|
+
checkPublicSuffix('b.test.om', 'b.test.om')
|
77
|
+
checkPublicSuffix('a.b.test.om', 'b.test.om')
|
78
|
+
checkPublicSuffix('songfest.om', 'songfest.om')
|
79
|
+
checkPublicSuffix('www.songfest.om', 'songfest.om')
|
80
|
+
# US K12.
|
81
|
+
checkPublicSuffix('us', 'NULL')
|
82
|
+
checkPublicSuffix('test.us', 'test.us')
|
83
|
+
checkPublicSuffix('www.test.us', 'test.us')
|
84
|
+
checkPublicSuffix('ak.us', 'NULL')
|
85
|
+
checkPublicSuffix('test.ak.us', 'test.ak.us')
|
86
|
+
checkPublicSuffix('www.test.ak.us', 'test.ak.us')
|
87
|
+
checkPublicSuffix('k12.ak.us', 'NULL')
|
88
|
+
checkPublicSuffix('test.k12.ak.us', 'test.k12.ak.us')
|
89
|
+
checkPublicSuffix('www.test.k12.ak.us', 'test.k12.ak.us')
|