myna_bird 0.1.0

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.
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## ECLIPSE
22
+ .project
23
+
24
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Brendan Schwartz
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 ADDED
@@ -0,0 +1,52 @@
1
+ ____ __
2
+ /'\_/`\ /\ _`\ __ /\ \
3
+ /\ \ __ __ ___ __ \ \ \L\ \ /\_\ _ __ \_\ \
4
+ \ \ \__\ \ /\ \/\ \ /' _ `\ /'__`\ \ \ _ <'\/\ \ /\`'__\/'_` \
5
+ \ \ \_/\ \\ \ \_\ \ /\ \/\ \ /\ \L\.\_\ \ \L\ \\ \ \\ \ \//\ \L\ \
6
+ \ \_\\ \_\\/`____ \\ \_\ \_\\ \__/.\_\\ \____/ \ \_\\ \_\\ \___,_\
7
+ \/_/ \/_/ `/___/> \\/_/\/_/ \/__/\/_/ \/___/ \/_/ \/_/ \/__,_ /
8
+ /\___/
9
+ \/__/
10
+
11
+ MynaBird converts email addresses into "account names" suitable for use in a
12
+ host name.
13
+
14
+ We use this here at Wistia. A user can sign up for an account using just
15
+ their email address, and in typical trendy SaaS fashion, they get an account
16
+ URL in the form of http://account-name.wistia.com. MynaBird performs the
17
+ conversion of their email into their new account name.
18
+
19
+ It works like this: if the domain is a that of a known ISP or email provider
20
+ (like Comcast or Gmail), then MynaBird uses the local part of their address as
21
+ the name. Otherwise, MynaBird builds the account name from the domain.
22
+
23
+ For example:
24
+
25
+ brendan@wistia.com -> wistia
26
+ brendan.schwartz@gmail.com -> brendan-schwartz
27
+ brendan+nospam@gmail.com -> brendan
28
+ support@gmail.com -> support-at-gmail
29
+
30
+ Ok, that last one is a bit of a special case, but you get the idea.
31
+
32
+
33
+ Usage:
34
+
35
+ require 'myna_bird'
36
+ MynaBird.convert('brendan@wistia.com') #=> 'wistia'
37
+
38
+
39
+ Specs:
40
+
41
+ Just run "rake spec" to run the specs.
42
+ Don't be shy, feel free to add more examples.
43
+
44
+
45
+ Questions:
46
+
47
+ Feel free to email me at brendan@wistia.com with any questions.
48
+
49
+
50
+ License:
51
+
52
+ Go nuts. See LICENSE for full details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "myna_bird"
8
+ gem.summary = %Q{Transform email addresses into account names for your app}
9
+ gem.description = %Q{Given an email address, MynaBird generates a name suitable for use in a host name}
10
+ gem.email = "bschwartz@wistia.com"
11
+ gem.homepage = "http://github.com/wistia/myna_bird"
12
+ gem.authors = ["Brendan Schwartz"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "myna_bird #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,83 @@
1
+ class MynaBird
2
+
3
+ COMMON_LOCALS = %w(
4
+ support info sales marketing admin webmaster help
5
+ )
6
+
7
+ COMMON_DOMAINS = %w(
8
+ hotmail msn live yahoo yahoo.co.uk ymail rocketmail gmail googlemail aol
9
+ fastmail.fm web mail.ru rediff indiatimes lycos libero.it rambler.ru mac
10
+ paracalls linkedin mynet interia.pl yandex.ru sina 126 lycos bol in me
11
+ voila.fr mail comcast netcom roadrunner verizon 1and1 att adelphia
12
+ bigpond bluebottle blueyonder btopenworld charter cox earthlink sbc telus
13
+ mailinator charter rogers sympatico tiscali
14
+ ) + [
15
+ /\.edu$/
16
+ ]
17
+
18
+ def self.convert(email)
19
+ new(email).name
20
+ end
21
+
22
+ def initialize(email)
23
+ @email = email.downcase
24
+ @local, @domain = @email.split('@')
25
+ end
26
+
27
+
28
+ # extract the name
29
+ def name
30
+ if common_local? && common_domain?
31
+ local_name + '-at-' + domain_name
32
+ elsif common_local?
33
+ domain_name
34
+ elsif common_domain?
35
+ local_name
36
+ else
37
+ domain_name
38
+ end
39
+ end
40
+
41
+ def domain_name
42
+ just_the_host = @domain.split('.').first
43
+ self.class.nameize(just_the_host)
44
+ end
45
+
46
+ def local_name
47
+ local_sans_alias = @local.gsub(/\+.*$/, '')
48
+ self.class.nameize(local_sans_alias)
49
+ end
50
+
51
+ def self.nameize(str)
52
+ name = str.downcase
53
+ name.gsub!(/[^a-z0-9]+/, '-')
54
+ name.gsub!(/\-$/,'')
55
+ name.gsub!(/^\-/,'')
56
+ name
57
+ end
58
+
59
+ def common_domain?
60
+ COMMON_DOMAINS.each do |domain|
61
+ if domain.is_a?(Regexp)
62
+ return true if domain.match(@domain)
63
+ else
64
+ return true if /^#{domain}\./.match(@domain)
65
+ end
66
+ end
67
+
68
+ return false
69
+ end
70
+
71
+ def common_local?
72
+ COMMON_LOCALS.each do |local|
73
+ if local.is_a?(Regexp)
74
+ return true if local.match(@local)
75
+ else
76
+ return true if local == @local
77
+ end
78
+ end
79
+
80
+ return false
81
+ end
82
+
83
+ end
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{myna_bird}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brendan Schwartz"]
12
+ s.date = %q{2010-10-21}
13
+ s.description = %q{Given an email address, MynaBird generates a name suitable for use in a host name}
14
+ s.email = %q{bschwartz@wistia.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/myna_bird.rb",
26
+ "myna_bird.gemspec",
27
+ "spec/myna_bird_spec.rb",
28
+ "spec/spec.opts",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/wistia/myna_bird}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{Transform email addresses into account names for your app}
36
+ s.test_files = [
37
+ "spec/myna_bird_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
47
+ else
48
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
52
+ end
53
+ end
54
+
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module ShouldConvert
4
+ def it_should_convert(from, to_hash)
5
+ to = to_hash[:to]
6
+ it "should convert '#{from}' to '#{to}'" do
7
+ MynaBird.convert(from) == to
8
+ end
9
+ end
10
+ end
11
+
12
+ describe MynaBird do
13
+ extend ShouldConvert
14
+
15
+ it_should_convert 'brendan@wistia.com', :to => 'wistia'
16
+ it_should_convert 'brendan.schwartz@gmail.com', :to => 'brendan-schwartz'
17
+ it_should_convert 'support@gmail.com', :to => 'support-at-gmail'
18
+
19
+ it_should_convert 'brendan....schwartz@gmail.com', :to => 'brendan-schwartz'
20
+ it_should_convert 'bts@alumni.brown.edu', :to => 'bts'
21
+ it_should_convert 'claire@megacorp.co.uk', :to => 'megacorp'
22
+ it_should_convert 'brendan19@aol.com', :to => 'brendan19'
23
+ it_should_convert 'brendan.@aol.com', :to => 'brendan'
24
+ it_should_convert '.brendan@aol.com', :to => 'brendan'
25
+ it_should_convert 'brendan+nospam@aol.com', :to => 'brendan'
26
+ it_should_convert 'BRENDAN@aol.com', :to => 'brendan'
27
+ it_should_convert 'brendan@WISTIA.COM', :to => 'wistia'
28
+
29
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'myna_bird'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: myna_bird
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Brendan Schwartz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-21 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Given an email address, MynaBird generates a name suitable for use in a host name
38
+ email: bschwartz@wistia.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README
46
+ files:
47
+ - .gitignore
48
+ - LICENSE
49
+ - README
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/myna_bird.rb
53
+ - myna_bird.gemspec
54
+ - spec/myna_bird_spec.rb
55
+ - spec/spec.opts
56
+ - spec/spec_helper.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/wistia/myna_bird
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Transform email addresses into account names for your app
91
+ test_files:
92
+ - spec/myna_bird_spec.rb
93
+ - spec/spec_helper.rb