domo-rb 0.0.1
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.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +34 -0
- data/Rakefile +10 -0
- data/domo.gemspec +25 -0
- data/lib/domo/version.rb +3 -0
- data/lib/domo.rb +39 -0
- data/spec/domo_spec.rb +25 -0
- data/spec/spec_helper.rb +6 -0
- metadata +75 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@domo --create
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Domo.rb
|
2
|
+
Utility functions for domain strings
|
3
|
+
|
4
|
+
### Installation
|
5
|
+
gem install domo
|
6
|
+
|
7
|
+
|
8
|
+
### Usage
|
9
|
+
>> require 'domo'
|
10
|
+
=> 'true'
|
11
|
+
|
12
|
+
>> Domo.canonize "www.ebay.com"
|
13
|
+
=> "ebay.com"
|
14
|
+
|
15
|
+
>> Domo.canonize "boats.ebay.co.uk"
|
16
|
+
=> "ebay.co.uk"
|
17
|
+
|
18
|
+
>> Domo.canonize "edition.cnn.com"
|
19
|
+
=> "cnn.com"
|
20
|
+
|
21
|
+
>> Domo.strip_url "http://www.cnn.com/news/last-week/main.html"
|
22
|
+
=> "www.cnn.com"
|
23
|
+
|
24
|
+
|
25
|
+
### Testing Notes
|
26
|
+
Install development dependencies with
|
27
|
+
|
28
|
+
bundle install
|
29
|
+
And run the tests with:
|
30
|
+
|
31
|
+
rake spec
|
32
|
+
|
33
|
+
|
34
|
+
Copyright (c) 2011 Gur Dotan, released under the MIT license.
|
data/Rakefile
ADDED
data/domo.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$:.push(lib) unless $:.include?(lib)
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require './lib/domo/version'
|
6
|
+
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "domo-rb"
|
10
|
+
s.version = Domo::VERSION
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
13
|
+
s.authors = ["Gur Dotan"]
|
14
|
+
s.email = "gurdotan@gmail.com"
|
15
|
+
s.homepage = "http://github.com/gurdotan/domo.rb"
|
16
|
+
s.summary = "Utility functions for domain strings"
|
17
|
+
s.require_path = ["lib"]
|
18
|
+
s.has_rdoc = false
|
19
|
+
s.extra_rdoc_files = ["README.md"]
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.required_rubygems_version = ">= 1.3.6"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
end
|
25
|
+
|
data/lib/domo/version.rb
ADDED
data/lib/domo.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "domo/version"
|
2
|
+
|
3
|
+
module Domo
|
4
|
+
|
5
|
+
GENERIC_TOP_LEVEL_DOMAINS = %W{ aero asia biz com coop edu gov info int jobs mil mobi museum name net org pro tel travel xxx }
|
6
|
+
GEO_TOP_LEVEL_DOMAINS = %W{ ac ad ae af ag ai al am an ao aq ar as at au aw ax az ba bb bd be bf bg bh bi bj bm bn bo br bs bt bv bw by bz ca cc cd cf cg ch ci ck cl cm cn co cr cs cu cv cx cy cz de dj dk dm do dz ec ee eg er es et eu fi fj fk fm fo fr ga gb gd ge gf gg gh gi gl gm gn gp gq gr gs gt gu gw gy hk hm hn hr ht hu id ie il im in io iq ir is it je jm jo jp ke kg kh ki km kn kp kr kw ky kz la lb lc li lk lr ls lt lu lv ly ma mc md me mg mh mk ml mm mn mo mp mq mr ms mt mu mv mw mx my mz na nc ne nf ng ni nl no np nr nu nz om pa pe pf pg ph pk pl pm pn pr ps pt pw py qa re ro rs ru rw sa sb sc sd se sg sh si sj sk sl sm sn so sr st su sv sy sz tc td tf tg th tj tk tl tm tn to tp tr tt tv tw tz ua ug uk us uy uz va vc ve vg vi vn vu wf ws ye yt za zm zw }
|
7
|
+
GEO_SPECIFIC_SECOND_LEVEL = %W{ co ac } # Not used in REGEX since it's included in the geo (co = Colombia, ac = Ascension Island)
|
8
|
+
|
9
|
+
REGEX = /^(#{GENERIC_TOP_LEVEL_DOMAINS.join("|")}|#{GEO_TOP_LEVEL_DOMAINS.join("|")})$/
|
10
|
+
|
11
|
+
# Returns a canonized domain for a given domain string
|
12
|
+
# Examples:
|
13
|
+
# "www.cnn.com" => "cnn.com"
|
14
|
+
# "books.ebay.co.uk" => "ebay.co.uk"
|
15
|
+
# "news.nytimes.com:3000" => "nytimes.com"
|
16
|
+
def self.canonize(domain)
|
17
|
+
parts = domain.split(":")[0].split(".").reverse
|
18
|
+
|
19
|
+
check_further = true
|
20
|
+
i = 0
|
21
|
+
while check_further
|
22
|
+
if parts[i] =~ REGEX
|
23
|
+
i += 1
|
24
|
+
else
|
25
|
+
check_further = false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
return parts[0..i].reverse.join(".")
|
30
|
+
end
|
31
|
+
|
32
|
+
def strip_url(url)
|
33
|
+
url[/:\/\/(.[^\/]+)/, 1]
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
include Domo
|
data/spec/domo_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),"spec_helper")
|
2
|
+
|
3
|
+
describe "Domo" do
|
4
|
+
|
5
|
+
it "should canonize 'www.ebay.com'" do
|
6
|
+
Domo.canonize("www.ebay.com").should == "ebay.com"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should canonize 'motors.ebay.com'" do
|
10
|
+
Domo.canonize("motors.ebay.com").should == "ebay.com"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should canonize 'www.ebay.co.uk'" do
|
14
|
+
Domo.canonize("www.ebay.co.uk").should == "ebay.co.uk"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should canonize 'ebay.com'" do
|
18
|
+
Domo.canonize("ebay.com").should == "ebay.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should strip 'http://www.ebay.com/shopping/1.html'" do
|
22
|
+
Domo.strip_url("http://www.ebay.com/shopping/1.html").should == "www.ebay.com"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: domo-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gur Dotan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-22 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
description:
|
28
|
+
email: gurdotan@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.md
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- .rvmrc
|
38
|
+
- Gemfile
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- domo.gemspec
|
42
|
+
- lib/domo.rb
|
43
|
+
- lib/domo/version.rb
|
44
|
+
- spec/domo_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/gurdotan/domo.rb
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- - lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.3.6
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.5.2
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Utility functions for domain strings
|
74
|
+
test_files: []
|
75
|
+
|