ryodo 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +111 -2
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/checks/matching.rb +6 -1
- data/lib/ryodo.rb +1 -0
- data/lib/ryodo/ext/uri.rb +12 -0
- data/lib/ryodo/rule_set.rb +0 -5
- data/ryodo.gemspec +2 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -8,7 +8,9 @@ This is a pure Ruby implementation of the [regdomr](https://github.com/asaaki/re
|
|
8
8
|
|
9
9
|
Without the Cext backend it should be also easily usable with Ruby implemenations like JRuby.
|
10
10
|
|
11
|
-
**Works only with Ruby 1.9.x!**
|
11
|
+
**Works only with Ruby 1.9.x!** (I dropped all support for 1.8.x)
|
12
|
+
|
13
|
+
|
12
14
|
|
13
15
|
## Usage
|
14
16
|
|
@@ -52,7 +54,7 @@ ryodo("my.awesome.domain.co.jp")
|
|
52
54
|
"my.awesome.domain.co.jp".ryodo
|
53
55
|
```
|
54
56
|
|
55
|
-
UTF-8 junkie?
|
57
|
+
### UTF-8 junkie?
|
56
58
|
|
57
59
|
```ruby
|
58
60
|
# encoding: utf-8
|
@@ -61,10 +63,117 @@ ryōdo("my.awesome.domain.co.jp")
|
|
61
63
|
りょうど("my.awesome.domain.co.jp")
|
62
64
|
```
|
63
65
|
|
66
|
+
### Extension of URI
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
require "regdomr/uri"
|
70
|
+
|
71
|
+
uri = URI.parse("http://my.awesome.domain.jp:5555/path")
|
72
|
+
uri.host
|
73
|
+
#=> "my.awesome.domain.jp"
|
74
|
+
|
75
|
+
uri.host.class
|
76
|
+
#=> Ryodo::Domain
|
77
|
+
# but decorates the String class transparently
|
78
|
+
|
79
|
+
uri.host.domain
|
80
|
+
#=> "domain.com"
|
81
|
+
```
|
82
|
+
|
83
|
+
In Gemfile:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
gem "ryodo", :require => ["ryodo","ryodo/ext/uri"]
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
## Benchmark
|
92
|
+
|
93
|
+
There is another gem called [public_suffix](https://github.com/weppos/public_suffix_service), which does nearly the same (maybe with more features I don't need).
|
94
|
+
|
95
|
+
So I did a tiny benchmark.
|
96
|
+
|
97
|
+
**Setup**
|
98
|
+
|
99
|
+
A domain input list, taken by publicsuffix.org (checkPublicSuffix test script under [publicsuffix.org/list/](http://publicsuffix.org/list/)).
|
100
|
+
|
101
|
+
Some of them are also invalid (to test, if you implementation works correctly).
|
102
|
+
|
103
|
+
I added some very long domain names with many parts (for look-up time scale).
|
104
|
+
|
105
|
+
Finally 72 entries to check.
|
106
|
+
|
107
|
+
Ruby: 1.9.3-p194, no special patches
|
108
|
+
|
109
|
+
We only do a basic parsing and retrieve the registered/registrable domain. (Should hit the most important code of the gems.)
|
110
|
+
|
111
|
+
**Test script snippet**
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
# DOMAINS is the array of domain entries - shuffled on every benchmark run
|
115
|
+
|
116
|
+
LOOPS = 1_000
|
117
|
+
|
118
|
+
Benchmark.bmbm do |b|
|
119
|
+
|
120
|
+
b.report "ryodo" do
|
121
|
+
LOOPS.times do
|
122
|
+
DOMAINS.each do |domain|
|
123
|
+
Ryodo.parse(domain).domain # returns nil if not valid
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
b.report "public_suffix" do
|
129
|
+
LOOPS.times do
|
130
|
+
DOMAINS.each do |domain|
|
131
|
+
PublicSuffix.parse(domain).domain rescue nil # it raises if not valid in any way, so we rescue it
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
**Caveats**
|
140
|
+
|
141
|
+
`PublicSuffix.parse(…)` will raise errors if domain input is invalid (e.g. not a registrable domain).
|
142
|
+
|
143
|
+
`Ryodo.parse(…)` won't raise but return nil values for invalid stuff (it only raises if input is not a String, of course).
|
144
|
+
|
145
|
+
**Result**
|
146
|
+
|
147
|
+
```
|
148
|
+
Rehearsal -------------------------------------------------
|
149
|
+
ryodo 1.800000 0.000000 1.800000 ( 1.809521)
|
150
|
+
public_suffix 21.880000 0.020000 21.900000 ( 21.907808)
|
151
|
+
--------------------------------------- total: 23.700000sec
|
152
|
+
|
153
|
+
user system total real
|
154
|
+
ryodo 1.770000 0.000000 1.770000 ( 1.769734)
|
155
|
+
public_suffix 22.320000 0.010000 22.330000 ( 22.346013)
|
156
|
+
```
|
157
|
+
|
158
|
+
As you can see, Ryodo is more than **10 times faster**.
|
159
|
+
|
160
|
+
_(Funfact: My first approach was 6 times slower — improvement factor of 60!)_
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
## TODO
|
166
|
+
|
167
|
+
Lot of specs missing, this first version of second approach was developed in playground mode. ;o)
|
168
|
+
|
169
|
+
|
170
|
+
|
64
171
|
## Foo …
|
65
172
|
|
66
173
|
"Uh, excuse me Sir … just one more question." — Columbo (Peter Falk †)
|
67
174
|
|
175
|
+
|
176
|
+
|
68
177
|
## License
|
69
178
|
|
70
179
|
MIT/X11 — see `LICENSE.txt`
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/checks/matching.rb
CHANGED
@@ -9,7 +9,7 @@ def checkPublicSuffix query, expectation
|
|
9
9
|
calculated = q.domain.nil? ? "NULL" : q.domain
|
10
10
|
passed = (calculated==expectation) ? " OK" : "FAIL"
|
11
11
|
|
12
|
-
puts "#{passed} === Q: #{query.ljust(
|
12
|
+
puts "#{passed} === Q: #{query.ljust(26)} | #{expectation.rjust(16)} <=> #{calculated.ljust(16)}"
|
13
13
|
end
|
14
14
|
|
15
15
|
# NULL input.
|
@@ -23,6 +23,11 @@ checkPublicSuffix('.com', 'NULL')
|
|
23
23
|
checkPublicSuffix('.example', 'NULL')
|
24
24
|
checkPublicSuffix('.example.com', 'NULL')
|
25
25
|
checkPublicSuffix('.example.example', 'NULL')
|
26
|
+
#Trailing dot (FQDN).
|
27
|
+
checkPublicSuffix('com.', 'NULL')
|
28
|
+
checkPublicSuffix('example.com.', 'example.com')
|
29
|
+
checkPublicSuffix('www.example.com.', 'example.com')
|
30
|
+
checkPublicSuffix('www.subdomain.example.com.', 'example.com')
|
26
31
|
# Unlisted TLD.
|
27
32
|
checkPublicSuffix('example', 'NULL')
|
28
33
|
checkPublicSuffix('example.example', 'NULL')
|
data/lib/ryodo.rb
CHANGED
data/lib/ryodo/rule_set.rb
CHANGED
@@ -9,7 +9,6 @@ module Ryodo
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def build!
|
12
|
-
|
13
12
|
Ryodo::SuffixList.list.each do |line|
|
14
13
|
|
15
14
|
line.each.with_index do |node_name, idx|
|
@@ -33,11 +32,9 @@ module Ryodo
|
|
33
32
|
end
|
34
33
|
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
38
36
|
|
39
37
|
def select_rule(rule_path)
|
40
|
-
|
41
38
|
path = rule_path.dup
|
42
39
|
|
43
40
|
if current = path.pop
|
@@ -51,7 +48,6 @@ module Ryodo
|
|
51
48
|
end
|
52
49
|
|
53
50
|
end
|
54
|
-
|
55
51
|
end
|
56
52
|
|
57
53
|
def match(path)
|
@@ -70,7 +66,6 @@ module Ryodo
|
|
70
66
|
if match && !match.children.keys.include?(domain[0]) && domain[0]
|
71
67
|
[ suffix, [domain.shift], domain ]
|
72
68
|
end
|
73
|
-
|
74
69
|
end
|
75
70
|
|
76
71
|
end
|
data/ryodo.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "ryodo"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Christoph Grabo"]
|
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
"lib/ryodo/convenience/.u.rb",
|
37
37
|
"lib/ryodo/domain.rb",
|
38
38
|
"lib/ryodo/ext/string.rb",
|
39
|
+
"lib/ryodo/ext/uri.rb",
|
39
40
|
"lib/ryodo/methods.rb",
|
40
41
|
"lib/ryodo/parser.rb",
|
41
42
|
"lib/ryodo/rule.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ryodo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/ryodo/convenience/.u.rb
|
151
151
|
- lib/ryodo/domain.rb
|
152
152
|
- lib/ryodo/ext/string.rb
|
153
|
+
- lib/ryodo/ext/uri.rb
|
153
154
|
- lib/ryodo/methods.rb
|
154
155
|
- lib/ryodo/parser.rb
|
155
156
|
- lib/ryodo/rule.rb
|
@@ -177,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
178
|
version: '0'
|
178
179
|
segments:
|
179
180
|
- 0
|
180
|
-
hash: -
|
181
|
+
hash: -130552580166080210
|
181
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
183
|
none: false
|
183
184
|
requirements:
|