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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 780cff4b58660435810a6ce1179f7de16dc0dd48
4
- data.tar.gz: 9fa8ec0c93eeb9c4b26dcee8caad53832b3a7bbe
3
+ metadata.gz: 94f4bdbb1c8f11c7c04d9c0e63ba955fa8806d09
4
+ data.tar.gz: 7b7218273f28bb9886429741536f72dd19bab3f8
5
5
  SHA512:
6
- metadata.gz: 9bf7d7006c2d4f61c3453b4540f85eb77ccb83b5bd030a22c8a0d6b7b39d9cbb7ea958ebbf5e53613a22d5784659d6d98290890621df3f32366dec33d6a329e7
7
- data.tar.gz: 05a179c7c807bc05c393a5932941d8ca6d84583901316eb57e805a1e0ca4d9e10dfa243bbee6d496794538b48d6ab1d441cc0b7417df94c025c1bb4ff3037ee8
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
- brendan@wistia.com -> wistia
29
- brendan.schwartz@gmail.com -> brendan-schwartz
30
- brendan+nospam@gmail.com -> brendan
31
- support@gmail.com -> support-at-gmail
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
- require 'myna_bird'
39
- MynaBird.convert('brendan@wistia.com') #=> 'wistia'
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
- Specs:
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.
@@ -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)
@@ -6,7 +6,7 @@
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "myna_bird"
9
- s.version = "0.2.11"
9
+ s.version = "0.2.12"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -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
@@ -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.11
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.4.6
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