myna_bird 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -10
- data/lib/myna_bird.rb +20 -2
- data/myna_bird.gemspec +1 -1
- data/spec/myna_bird_spec.rb +6 -0
- data/spec/spec_helper.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94f4bdbb1c8f11c7c04d9c0e63ba955fa8806d09
|
4
|
+
data.tar.gz: 7b7218273f28bb9886429741536f72dd19bab3f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82d99f2f9dd2d293c2392361e9f9a2d5228c912d9590494f77fd58e7e233b77ab58dbae6ec9f89cfd8e83edcc414a94cd63974c98ba407d21ff8e709610009bf
|
7
|
+
data.tar.gz: 0abe86d1e15fc5193243c6d81ba04374af554fd06c3334c16e2afa841ec80ad08e55b3682a9a187a217fc4d73d652304fcd98ae87af2bb1570bb12d325b84c1d
|
data/README.md
CHANGED
@@ -25,31 +25,37 @@ the name. Otherwise, MynaBird builds the account name from the domain.
|
|
25
25
|
|
26
26
|
For example:
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
brendan@wistia.com -> wistia
|
29
|
+
brendan.schwartz@gmail.com -> brendan-schwartz
|
30
|
+
brendan+nospam@gmail.com -> brendan
|
31
|
+
support@gmail.com -> support-at-gmail
|
32
32
|
|
33
33
|
Ok, that last one is a bit of a special case, but you get the idea.
|
34
34
|
|
35
35
|
|
36
|
-
Usage
|
36
|
+
## Usage
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
require 'myna_bird'
|
39
|
+
MynaBird.convert('brendan@wistia.com') #=> 'wistia'
|
40
40
|
|
41
|
+
You can also tell MynaBird to avoid a list of domains. No need to include the
|
42
|
+
TLD, just a second-level domain. For example:
|
41
43
|
|
42
|
-
|
44
|
+
MynaBird.avoid_domains = ['coolmail', 'bestmail']
|
45
|
+
MynaBird.convert('best.business@coolmail.com') #=> 'best-business'
|
46
|
+
|
47
|
+
|
48
|
+
## Specs
|
43
49
|
|
44
50
|
Just run "rake spec" to run the specs.
|
45
51
|
Don't be shy, feel free to add more examples.
|
46
52
|
|
47
53
|
|
48
|
-
Questions
|
54
|
+
## Questions
|
49
55
|
|
50
56
|
Feel free to email me at brendan@wistia.com with any questions.
|
51
57
|
|
52
58
|
|
53
|
-
License:
|
59
|
+
## License:
|
54
60
|
|
55
61
|
Go nuts. See LICENSE for full details.
|
data/lib/myna_bird.rb
CHANGED
@@ -24,6 +24,18 @@ class MynaBird
|
|
24
24
|
new(email).name
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.reset_avoided_domains
|
28
|
+
@avoided_domains = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.avoided_domains=(domains)
|
32
|
+
@avoided_domains = domains
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.avoided_domains
|
36
|
+
@avoided_domains || []
|
37
|
+
end
|
38
|
+
|
27
39
|
def initialize(email)
|
28
40
|
# email must be in a somewhat sane format
|
29
41
|
# i.e. have an @ sign and at least one letter or number on each side of it
|
@@ -36,11 +48,11 @@ class MynaBird
|
|
36
48
|
|
37
49
|
# extract the name
|
38
50
|
def name
|
39
|
-
if common_local? && common_domain?
|
51
|
+
if common_local? && (common_domain? || avoided_domain?)
|
40
52
|
local_name + '-at-' + domain_name
|
41
53
|
elsif common_local?
|
42
54
|
domain_name
|
43
|
-
elsif common_domain?
|
55
|
+
elsif (common_domain? || avoided_domain?)
|
44
56
|
local_name
|
45
57
|
else
|
46
58
|
domain_name
|
@@ -65,6 +77,12 @@ class MynaBird
|
|
65
77
|
name
|
66
78
|
end
|
67
79
|
|
80
|
+
def avoided_domain?
|
81
|
+
self.class.avoided_domains.any? do |domain|
|
82
|
+
/#{domain}/.match(@domain)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
68
86
|
def common_domain?
|
69
87
|
COMMON_DOMAINS.each do |domain|
|
70
88
|
if domain.is_a?(Regexp)
|
data/myna_bird.gemspec
CHANGED
data/spec/myna_bird_spec.rb
CHANGED
@@ -26,4 +26,10 @@ describe MynaBird do
|
|
26
26
|
it_should_not_convert '@@@@'
|
27
27
|
it_should_not_convert '++@++'
|
28
28
|
|
29
|
+
context 'domain should be avoided' do
|
30
|
+
it 'uses the local name' do
|
31
|
+
MynaBird.avoided_domains = ['post-jazz']
|
32
|
+
MynaBird.convert('davej@post-jazz.no').should == 'davej'
|
33
|
+
end
|
34
|
+
end
|
29
35
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,7 @@ require 'rspec'
|
|
5
5
|
|
6
6
|
module ShouldAndShouldNotConvert
|
7
7
|
def it_should_convert(from, to_hash)
|
8
|
-
to = to_hash[:to]
|
8
|
+
to = to_hash[:to]
|
9
9
|
it "should convert '#{from}' to '#{to}'" do
|
10
10
|
MynaBird.convert(from).should == to
|
11
11
|
end
|
@@ -22,4 +22,7 @@ end
|
|
22
22
|
|
23
23
|
RSpec.configure do |config|
|
24
24
|
config.extend(ShouldAndShouldNotConvert)
|
25
|
+
config.after do
|
26
|
+
MynaBird.reset_avoided_domains
|
27
|
+
end
|
25
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myna_bird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brendan Schwartz
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.2.3
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: Transform email addresses into account names for your app
|