Skip to content

Commit

Permalink
Merge pull request #8 from Applifting/dev
Browse files Browse the repository at this point in the history
Remove digits from name
  • Loading branch information
Vratislav committed Mar 28, 2016
2 parents 1513bee + 165a0e4 commit 87f0f7e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ParseNameFromEmail.get_email_name('[email protected]') # => 'john-s
ParseNameFromEmail.parse_name_from('[email protected]') # => 'John Snow'
ParseNameFromEmail.parse_name_from('[email protected]') # => 'John Snow'
ParseNameFromEmail.parse_name_from('[email protected]') # => 'John Snow'
ParseNameFromEmail.parse_name_from('[email protected]') # => 'John 123 Snow'
ParseNameFromEmail.parse_name_from('[email protected]') # => 'John Snow'
ParseNameFromEmail.parse_name_from('John Snow <[email protected]>') # => 'John Snow'

# validating RFC format of email
Expand All @@ -74,10 +74,10 @@ ParseNameFromEmail.parse_name_from('[email protected]') # => 'Joh

# batches
string_with_emails = 'John Snow <[email protected]>, [email protected]'
ParseNameFromEmail.parse_names_from(string_with_emails) # => ['John Snow', 'Alice 123']
ParseNameFromEmail.parse_names_from(string_with_emails) # => ['John Snow', 'Alice']

string_with_emails = '[email protected], [email protected]'
ParseNameFromEmail.parse_names_from(string_with_emails) # => ['Lily (black)', 'Alice 123']
ParseNameFromEmail.parse_names_from(string_with_emails) # => ['Lily (black)', 'Alice']

# advanced parsing
string_with_emails = '[email protected], [email protected]'
Expand Down
2 changes: 1 addition & 1 deletion lib/parse_name_from_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def split_to_words(email_name)
# after regex join it with blank space and upcase first letters
def make_human_readable(array)
humanized_elements = array.map { |el| el.strip.humanize }
humanized_elements.reject(&:empty?).join(' ')
humanized_elements.reject(&:empty?).reject{ |str| str =~ /\d/ }.join(' ')
end

# match regexp if is valid rfc format
Expand Down
2 changes: 1 addition & 1 deletion lib/parse_name_from_email/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Configuration
attr_accessor :regexp, :friendly_plus_part

def initialize
# split email address with regexp
# split email address with regexp (test: https://regex101.com/r/pF5mS4)
@regexp = /(?=[A-Z])|(?:([0-9]+))|\.|-|\?|!|\+|\;|\_/

## Recognizing plus parts in gmail addresses
Expand Down
2 changes: 1 addition & 1 deletion lib/parse_name_from_email/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ParseNameFromEmail
VERSION = '0.1.1'.freeze
VERSION = '0.2.0'.freeze
end
19 changes: 12 additions & 7 deletions spec/parse_name_from_email/parse_name_from_email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

it 'should parse by set of numbers' do
email = '[email protected]'
expect(parse_name_from_email.parse_name_from(email)).to eq 'Some 123 Email'
expect(parse_name_from_email.parse_name_from(email)).to eq 'Some Email'
end

it 'should parse by big chars' do
Expand All @@ -116,6 +116,11 @@
expect(parse_name_from_email.parse_name_from(email)).to eq 'Some (email)'
end

it 'should friendly parse by \+ with numbers' do
email = '[email protected]'
expect(parse_name_from_email.parse_name_from(email)).to eq 'Some (email123)'
end

it 'should not friendly parse by \+ if not configured' do
parse_name_from_email.configure do |config|
config.friendly_plus_part = false
Expand All @@ -141,17 +146,17 @@

it 'should valid parse names from rfc emails, but some email is without name' do
string_with_emails = 'John Snow <[email protected]>, Lily Black <[email protected]>, [email protected]'
expect(parse_name_from_email.parse_names_from(string_with_emails)).to eq ['John Snow', 'Lily Black', 'Alice 123']
expect(parse_name_from_email.parse_names_from(string_with_emails)).to eq ['John Snow', 'Lily Black', 'Alice']
end

it 'should valid parse names in non rfc format of emails' do
string_with_emails = '[email protected], [email protected], [email protected]'
expect(parse_name_from_email.parse_names_from(string_with_emails)).to eq ['John Snow', 'Lily Black', 'Alice 123']
expect(parse_name_from_email.parse_names_from(string_with_emails)).to eq ['John Snow', 'Lily Black', 'Alice']
end

it 'should valid parse names in non rfc format of emails and any email is with \+' do
string_with_emails = '[email protected], [email protected], [email protected]'
expect(parse_name_from_email.parse_names_from(string_with_emails)).to eq ['John Snow', 'Lily (black)', 'Alice 123']
expect(parse_name_from_email.parse_names_from(string_with_emails)).to eq ['John Snow', 'Lily (black)', 'Alice']
end
end

Expand All @@ -172,21 +177,21 @@

it 'should valid parse names from rfc emails, but some email is without name' do
string_with_emails = 'John Snow <[email protected]>, Lily Black <[email protected]>, [email protected]'
expected_hash = { '[email protected]' => 'John Snow', '[email protected]' => 'Lily Black', '[email protected]' => 'Alice 123' }
expected_hash = { '[email protected]' => 'John Snow', '[email protected]' => 'Lily Black', '[email protected]' => 'Alice' }

expect(parse_name_from_email.parse_emails_with_names_from(string_with_emails)).to eq expected_hash
end

it 'should valid parse names in non rfc format of emails' do
string_with_emails = '[email protected], [email protected], [email protected]'
expected_hash = { '[email protected]' => 'John Snow', '[email protected]' => 'Lily Black', '[email protected]' => 'Alice 123' }
expected_hash = { '[email protected]' => 'John Snow', '[email protected]' => 'Lily Black', '[email protected]' => 'Alice' }

expect(parse_name_from_email.parse_emails_with_names_from(string_with_emails)).to eq expected_hash
end

it 'should valid parse names in non rfc format of emails and any email is with \+' do
string_with_emails = '[email protected], [email protected], [email protected]'
expected_hash = { '[email protected]' => 'John Snow', '[email protected]' => 'Lily (black)', '[email protected]' => 'Alice 123' }
expected_hash = { '[email protected]' => 'John Snow', '[email protected]' => 'Lily (black)', '[email protected]' => 'Alice' }

expect(parse_name_from_email.parse_emails_with_names_from(string_with_emails)).to eq expected_hash
end
Expand Down

0 comments on commit 87f0f7e

Please sign in to comment.