This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
89 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem 'nokogiri' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
mini_portile (0.6.0) | ||
nokogiri (1.6.3.1) | ||
mini_portile (= 0.6.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
nokogiri |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'open-uri' | ||
require 'nokogiri' | ||
require 'yaml' | ||
|
||
namespace :tlds do | ||
desc 'Grab tlds from iana and save to tld_lib.yml' | ||
task :iana_update do | ||
doc = Nokogiri::HTML(open('http://www.iana.org/domains/root/db')) | ||
tlds = [] | ||
types = { | ||
'country' => /country-code/, | ||
'generic' => /generic|sponsored|infrastructure|generic-restricted/, | ||
} | ||
|
||
doc.css('table#tld-table tr').each do |tr| | ||
info = tr.css('td') | ||
next if info.empty? | ||
|
||
tlds << { | ||
domain: info[0].text.gsub('.', ''), | ||
type: info[1].text | ||
} | ||
end | ||
|
||
def select_tld(tlds, type) | ||
tlds.select {|i| i[:type] =~ type}.map {|i| i[:domain]}.sort | ||
end | ||
|
||
yml = {} | ||
types.each do |name, regex| | ||
yml[name] = select_tld(tlds, regex) | ||
end | ||
|
||
File.open(repo_path('tld_lib.yml'), 'w') do |file| | ||
file.write(yml.to_yaml) | ||
end | ||
end | ||
|
||
desc 'Update tests from tld_lib.yml' | ||
task :generate_tests do | ||
test_yml = { 'tests' => { } } | ||
|
||
path = repo_path('tld_lib.yml') | ||
yml = YAML.load_file(path) | ||
yml.each do |type, tlds| | ||
test_yml['tests'][type] = [] | ||
tlds.each do |tld| | ||
test_yml['tests'][type].push( | ||
'description' => "#{tld} is a valid #{type} tld", | ||
'text' => "https://twitter.#{tld}", | ||
'expected' => ["https://twitter.#{tld}"], | ||
) | ||
end | ||
end | ||
|
||
File.open('tlds.yml', 'w') do |file| | ||
file.write(test_yml.to_yaml) | ||
end | ||
end | ||
end | ||
|
||
def repo_path(*path) | ||
File.join(File.dirname(__FILE__), *path) | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters