<commit_before># ParseNameFromEmail

[![Build Status](https://travis-ci.org/Applifting/parse_name_from_email.svg?branch=master)](https://travis-ci.org/Applifting/parse_name_from_email)
[![Coverage Status](https://coveralls.io/repos/github/Applifting/parse_name_from_email/badge.svg?branch=master)](https://coveralls.io/github/Applifting/parse_name_from_email?branch=master)

This gem for easy way to parse email address or name from string of them.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'parse_name_from_email'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install parse_name_from_email

## Configuration

You don't need to configure anymore, but if you want to configure yourself, you can change this values:

```ruby
ParseNameFromEmail.configure do |config|
  # split email address with regexp
  config.regexp = /(?=[A-Z])|(?:([0-9]+))|\.|-|\?|!|\+|\;|\_/

  ## Recognizing plus parts in gmail addresses
  #
  # DEFAULT: true
  #
  # if TRUE:
  #   email address:  '<EMAIL>'
  #   result name:    'Example (Something 123)'
  #
  # if FALSE:
  #   email address:  '<EMAIL>'
  #   result name:    'Example Something 123'
  config.friendly_plus_part = true
end
```

Values above are default.

## Usage

```ruby
ParseNameFromEmail.get_email_name('<EMAIL>') # => 'john-snow'
ParseNameFromEmail.get_email_name('<EMAIL>') # => 'john-snow+nickname'

ParseNameFromEmail.valid_rfc_format?('<EMAIL>') # => false
ParseNameFromEmail.valid_rfc_format?('<NAME> <<EMAIL>>') # => true


ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME>'
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME>'
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME>'
ParseNameFromEmail.parse_name_from('<EMAIL>') # => 'John <NAME>'
ParseNameFromEmail.parse_name_from('<NAME> <<EMAIL>>') # => '<NAME>'

# if config.friendly_plus_part = true
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME> (Nickname 123)'

# if config.friendly_plus_part = false
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME> Nickname 123'

# batches
string_with_emails = '<NAME> <<EMAIL>>, <NAME> <<EMAIL>>, <EMAIL>.123@3x4mpl3.app'
ParseNameFromEmail.parse_names_from(string_with_emails) # => ['<NAME>', '<NAME>', 'Alice 123']

string_with_emails = '<EMAIL>, <EMAIL>, alice.123@3x4mpl3.app'
ParseNameFromEmail.parse_names_from(string_with_emails) # => ['<NAME>', 'Lily (black)', 'Alice 123']

# advanced parsing
string_with_emails = '<EMAIL>, <EMAIL>, alice.123@3x4mpl3.app'
ParseNameFromEmail.parse_emails_with_names_from(string_with_emails) # => {'<EMAIL>' => '<NAME>', '<EMAIL>' => 'Lily (black)', '<EMAIL>.12<EMAIL>' => '<NAME>'}

```<commit_msg>shorter readme<commit_after># ParseNameFromEmail

[![Build Status](https://travis-ci.org/Applifting/parse_name_from_email.svg?branch=master)](https://travis-ci.org/Applifting/parse_name_from_email)
[![Coverage Status](https://coveralls.io/repos/github/Applifting/parse_name_from_email/badge.svg?branch=master)](https://coveralls.io/github/Applifting/parse_name_from_email?branch=master)

This gem for easy way to parse email address or name from string of them.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'parse_name_from_email'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install parse_name_from_email

## Configuration

You don't need to configure anymore, but if you want to configure yourself, you can change this values:

```ruby
ParseNameFromEmail.configure do |config|
  # split email address with regexp
  config.regexp = /(?=[A-Z])|(?:([0-9]+))|\.|-|\?|!|\+|\;|\_/

  ## Recognizing plus parts in gmail addresses
  #
  # DEFAULT: true
  #
  # if TRUE:
  #   email address:  '<EMAIL>'
  #   result name:    'Example (Something 123)'
  #
  # if FALSE:
  #   email address:  '<EMAIL>'
  #   result name:    'Example Something 123'
  config.friendly_plus_part = true
end
```

Values above are default.

## Usage

```ruby
# getting email address
ParseNameFromEmail.get_email_name('<EMAIL>') # => 'john-snow'
ParseNameFromEmail.get_email_name('<EMAIL>') # => 'john-snow+nickname'

# parsing name from email address
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME>'
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME>'
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME>'
ParseNameFromEmail.parse_name_from('<EMAIL>') # => 'John <NAME>'
ParseNameFromEmail.parse_name_from('<NAME> <<EMAIL>>') # => '<NAME>'

# validating RFC format of email
ParseNameFromEmail.valid_rfc_format?('<EMAIL>') # => false
ParseNameFromEmail.valid_rfc_format?('<NAME> <<EMAIL>>') # => true

# if config.friendly_plus_part = true
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME> (Nickname 123)'

# if config.friendly_plus_part = false
ParseNameFromEmail.parse_name_from('<EMAIL>') # => '<NAME> Nickname 123'

# batches
string_with_emails = '<NAME> <<EMAIL>>, <EMAIL>'
ParseNameFromEmail.parse_names_from(string_with_emails) # => ['<NAME>', 'Alice 123']

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

# advanced parsing
string_with_emails = '<EMAIL>, <EMAIL>'
ParseNameFromEmail.parse_emails_with_names_from(string_with_emails)
# => {'<EMAIL>' => '<NAME>', '<EMAIL>' => 'Lily (black)'}

```
{'fraction_non_alphanumeric': 0.1689745508982036, 'fraction_numerical': 0.01122754491017964, 'mean_word_length': 5.861360718870347, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 116, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4751337', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1862, 'n_words': 370}