parse_name_from_email 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12cf43df5d9ea07c1981fcf3ca96675a811e7301
4
- data.tar.gz: c13cbc25b6c11f619d85b2381c570a18a9cfcef0
3
+ metadata.gz: 4ee897aba1e60e21402a1cf07fcc85ab8e123184
4
+ data.tar.gz: fc113234ab0becf423fec1ffc4a0662f766bf2b5
5
5
  SHA512:
6
- metadata.gz: 04d02316ed73a65b843d3373736335033ae288f4febedcfb627f1a3b4e2ff3dd62dd9b9ae5e1b7ad50ce2046f556cf3694ae894725efd998ecd217b9424f81cb
7
- data.tar.gz: 34260e35192e73cb7289a66fbc5c8708ffd9766f50170b116c6389e763d5144c101886e590db7fe91720bb6ea075073c2ca41095ce6ee22400baf8cff4e7a2b6
6
+ metadata.gz: 996df631c20f641e84ba590057f9fec3383fd29ceaf0073df4289de588aa1cbb3b52e5373e1d3773ae006cf2c75e0f566725b44e0b74ca8f1fba32a47aac6717
7
+ data.tar.gz: 4bd4b45421fd8af03941a9bc2755880d8aaa944ffc6339d00900711cbe498877c3337ec025938c9dd14804274dc6f96cfa637a44c1c6317e1fa1854b0dd09cb3
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse_name_from_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prokop Simek, Applifting
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-08 00:00:00.000000000 Z
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.1'
26
+ version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,21 +58,7 @@ email:
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
- files:
62
- - ".coveralls.yml"
63
- - ".gitignore"
64
- - ".travis.yml"
65
- - Gemfile
66
- - LICENSE.txt
67
- - README.md
68
- - Rakefile
69
- - bin/console
70
- - bin/setup
71
- - lib/parse_name_from_email.rb
72
- - lib/parse_name_from_email/batch.rb
73
- - lib/parse_name_from_email/configuration.rb
74
- - lib/parse_name_from_email/version.rb
75
- - parse_name_from_email.gemspec
61
+ files: []
76
62
  homepage: https://github.com/Applifting/parse_name_from_email
77
63
  licenses:
78
64
  - MIT
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- service_name: travis-ci
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /.idea
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.0
5
- - 2.1
6
- - 2.2
7
- - 2.2.3
8
- - 2.3.1
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in parse_name_from_email.gemspec
4
- gemspec
5
-
6
- gem 'rspec'
7
- gem 'coveralls', require: false
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Prokop Simek, Applifting
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,103 +0,0 @@
1
- # ParseNameFromEmail
2
-
3
- [![Gem Version](https://badge.fury.io/rb/parse_name_from_email.svg)](https://badge.fury.io/rb/parse_name_from_email)
4
- [![Build Status](https://travis-ci.org/Applifting/parse_name_from_email.svg?branch=master)](https://travis-ci.org/Applifting/parse_name_from_email)
5
- [![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)
6
-
7
- Rails gem to easily parse user name from email address.
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- ```ruby
14
- gem 'parse_name_from_email'
15
- ```
16
-
17
- And then execute:
18
-
19
- $ bundle
20
-
21
- Or install it yourself as:
22
-
23
- $ gem install parse_name_from_email
24
-
25
- ## Configuration
26
-
27
- You don't need to configure anything, but if you want to customize the behaviour, use the following snippet:
28
-
29
- ```ruby
30
- ParseNameFromEmail.configure do |config|
31
- # split email address with regexp
32
- config.regexp = /(?=[A-Z])|(?:([0-9]+))|\.|-|\?|!|\+|\;|\_/
33
-
34
- ## Recognizing plus parts in gmail addresses
35
- #
36
- # DEFAULT: true
37
- #
38
- # if TRUE:
39
- # email address: 'example+something123@gmail.com'
40
- # result name: 'Example (Something 123)'
41
- #
42
- # if FALSE:
43
- # email address: 'example+something123@gmail.com'
44
- # result name: 'Example'
45
- config.friendly_plus_part = true
46
- end
47
- ```
48
-
49
- Values in the above snippet are the default values.
50
-
51
- ## Usage
52
-
53
- ```ruby
54
- # getting email address
55
- ParseNameFromEmail.get_email_name('john-snow@example.com') # => 'john-snow'
56
- ParseNameFromEmail.get_email_name('john-snow+nickname@example.com') # => 'john-snow+nickname'
57
-
58
- # parsing name from email address
59
- ParseNameFromEmail.parse_name_from('JohnSnow@example.com') # => 'John Snow'
60
- ParseNameFromEmail.parse_name_from('john-snow@example.com') # => 'John Snow'
61
- ParseNameFromEmail.parse_name_from('john_snow@example.com') # => 'John Snow'
62
- ParseNameFromEmail.parse_name_from('john123snow@example.com') # => 'John Snow'
63
- ParseNameFromEmail.parse_name_from('John Snow <john.snow@example.com>') # => 'John Snow'
64
-
65
- # validating RFC format of email
66
- ParseNameFromEmail.valid_rfc_format?('john-snow@example.com') # => false
67
- ParseNameFromEmail.valid_rfc_format?('John Snow <john.snow@example.com>') # => true
68
-
69
- # if config.friendly_plus_part = true
70
- ParseNameFromEmail.parse_name_from('JohnSnow+Nickname123@example.com') # => 'John Snow (Nickname 123)'
71
-
72
- # if config.friendly_plus_part = false
73
- ParseNameFromEmail.parse_name_from('JohnSnow+Nickname123@example.com') # => 'John Snow'
74
-
75
- # batches
76
- string_with_emails = 'John Snow <john.snow@example.com>, alice.123@3x4mpl3.app'
77
- ParseNameFromEmail.parse_names_from(string_with_emails) # => ['John Snow', 'Alice']
78
-
79
- string_with_emails = 'lily+black@example.com, alice.123@3x4mpl3.app'
80
- ParseNameFromEmail.parse_names_from(string_with_emails) # => ['Lily (black)', 'Alice']
81
-
82
- # advanced parsing
83
- string_with_emails = 'john.snow@example.com, lily+black@example.com'
84
- ParseNameFromEmail.parse_emails_with_names_from(string_with_emails)
85
- # => {'john.snow@example.com' => 'John Snow', 'lily+black@example.com' => 'Lily (black)'}
86
-
87
- ```
88
-
89
- ## Development
90
-
91
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
-
93
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
-
95
- ## Contributing
96
-
97
- Bug reports and pull requests are welcome on GitHub at https://github.com/Applifting/parse_name_from_email.
98
-
99
-
100
- ## License
101
-
102
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
103
-
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- task default: :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'parse_name_from_email'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,9 +0,0 @@
1
- module ParseNameFromEmail
2
- class Batch
3
- class << self
4
- def split_emails_to_array(string_with_emails)
5
- string_with_emails.split(/\;|\,/)
6
- end
7
- end
8
- end
9
- end
@@ -1,31 +0,0 @@
1
- module ParseNameFromEmail
2
- class Configuration
3
- attr_accessor :regexp, :friendly_plus_part
4
-
5
- def initialize
6
- # split email address with regexp (test: https://regex101.com/r/pF5mS4)
7
- @regexp = /(?=[A-Z])|(?:([0-9]+))|\.|-|\?|!|\+|\;|\_/
8
-
9
- ## Recognizing plus parts in gmail addresses
10
- #
11
- # DEFAULT: true
12
- #
13
- # if TRUE:
14
- # email address: 'example+something123@gmail.com'
15
- # result name: 'Example (Something 123)'
16
- #
17
- # if FALSE:
18
- # email address: 'example+something123@gmail.com'
19
- # result name: 'Example'
20
- @friendly_plus_part = true
21
- end
22
-
23
- def self.regexp_to_split_by_rfc
24
- /(\<|\>)/
25
- end
26
-
27
- def self.regex_for_validation_format_as_rfc
28
- /(\<[\S]*[\S]*\.[\S]*\>)/
29
- end
30
- end
31
- end
@@ -1,3 +0,0 @@
1
- module ParseNameFromEmail
2
- VERSION = '1.0.2'.freeze
3
- end
@@ -1,110 +0,0 @@
1
- require 'active_support/all'
2
-
3
- require 'parse_name_from_email/version'
4
- require 'parse_name_from_email/configuration'
5
- require 'parse_name_from_email/batch'
6
-
7
- module ParseNameFromEmail
8
- class << self
9
- def configuration
10
- @configuration ||= Configuration.new
11
- end
12
-
13
- def reset
14
- @configuration = Configuration.new
15
- end
16
-
17
- def configure
18
- yield(configuration)
19
- end
20
-
21
- # parses string of multiple emails to hash of emails and generated names
22
- def parse_emails_with_names_from(string_with_emails)
23
- emails = Batch.split_emails_to_array(string_with_emails)
24
- result = {}
25
- emails.each { |email| result[get_email_address(email)] = parse_name_from(email) }
26
- result
27
- end
28
-
29
- # parses string of multiple emails to array of names
30
- def parse_names_from(string_with_emails)
31
- emails = Batch.split_emails_to_array(string_with_emails)
32
- result = []
33
- emails.each { |email| result << parse_name_from(email) }
34
- result
35
- end
36
-
37
- # main logic of parsing one email address
38
- def parse_name_from(email)
39
- # if emails is in RFC format, return the name if not blank
40
- name_from_rfc = get_name_if_rfc_format_of_email(email)
41
- return name_from_rfc unless name_from_rfc.blank?
42
-
43
- # get part before '@'
44
- email_name = get_email_name(email)
45
-
46
- splitted_by_plus = split_plus_part(email_name) # get part before and after plus part
47
-
48
- # if friendly plus part, make result more readable
49
- if splitted_by_plus.size >= 2
50
- email_name = splitted_by_plus[0...-1].join(' ') # reject part after plus and overwrite it joined to string
51
- if configuration.friendly_plus_part
52
- plus_part = splitted_by_plus.last # last part is after plus and it should be gmail nickname
53
- end
54
- end
55
-
56
- splitted_email = split_to_words(email_name) # split email name by regex
57
-
58
- name = make_human_readable(splitted_email) # join email name with space
59
-
60
- # add part after plus
61
- if configuration.friendly_plus_part && !plus_part.blank?
62
- name += ' ' unless name.blank?
63
- name += "(#{plus_part})" unless plus_part.blank?
64
- end
65
-
66
- name # return result
67
- end
68
-
69
- # split email by '@' and get only email name
70
- def get_email_name(email)
71
- email.split('@').first
72
- end
73
-
74
- # is rfc format? if true, return me only the email address
75
- def get_email_address(email)
76
- if valid_rfc_format?(email)
77
- email = email.split(/\</).last.to_s.delete('>')
78
- end
79
- email.strip
80
- end
81
-
82
- # if is rfc format of email, returns only name
83
- def get_name_if_rfc_format_of_email(email)
84
- name = email.split(/\</).first.to_s.strip if valid_rfc_format?(email)
85
- name
86
- end
87
-
88
- # split email plus part
89
- def split_plus_part(email)
90
- email.split('+')
91
- end
92
-
93
- # split email by regex
94
- def split_to_words(email_name)
95
- email_name.split(configuration.regexp)
96
- end
97
-
98
- # after regex join it with blank space and upcase first letters
99
- def make_human_readable(array)
100
- humanized_elements = array.map { |el| el.strip.humanize }
101
- humanized_elements.reject(&:empty?).reject{ |str| str =~ /\d/ }.join(' ')
102
- end
103
-
104
- # match regexp if is valid rfc format
105
- def valid_rfc_format?(email)
106
- match = (email =~ Configuration.regex_for_validation_format_as_rfc)
107
- match.present?
108
- end
109
- end
110
- end
@@ -1,34 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'parse_name_from_email/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'parse_name_from_email'
8
- spec.version = ParseNameFromEmail::VERSION
9
- spec.authors = ['Prokop Simek, Applifting']
10
- spec.email = ['prokop.simek@applifting.cz']
11
-
12
- spec.summary = 'Parse name from email address.'
13
- spec.description = 'This gem makes it easy to parse name from email addresses.'
14
- spec.homepage = 'https://github.com/Applifting/parse_name_from_email'
15
- spec.license = 'MIT'
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'exe'
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ['lib']
21
-
22
- spec.required_ruby_version = '>= 2.0'
23
-
24
- if RUBY_VERSION >= '2.3'
25
- spec.add_dependency 'activesupport'
26
- elsif RUBY_VERSION >= '2.1'
27
- spec.add_dependency 'activesupport', '~> 4.1'
28
- elsif RUBY_VERSION < '2.1'
29
- spec.add_dependency 'activesupport', '~> 3.2'
30
- end
31
-
32
- spec.add_development_dependency 'bundler'
33
- spec.add_development_dependency 'rake'
34
- end