emiler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b8779ed5ed7a15142398296cbd9c4338c768a7f
4
+ data.tar.gz: e8290f544838222b96e34bbcccd4b58af982ba28
5
+ SHA512:
6
+ metadata.gz: 645a20b05c46357a5b91e22aae4e6ae93c8ea6d1ffed6d4a922ccfb958720ba8919a554a630028003be97fbe9517fb44c4407003b220cc0c39399bf4ed1949d3
7
+ data.tar.gz: 3c69442320ddb491a659e384c09e2218ca6ce4980ec47234bcb374027cb2f195dc62e3ec92448f726a4c00e440218709eedde135e0d2fc2ff10738e3afdf0212
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,53 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Style/HashSyntax:
4
+ EnforcedStyle: ruby19
5
+
6
+ Style/MethodDefParentheses:
7
+ Exclude:
8
+ - 'lib/**/*'
9
+ - 'spec/**/*'
10
+
11
+ Style/AsciiIdentifiers:
12
+ Exclude:
13
+ - 'lib/**/*'
14
+ - 'spec/**/*'
15
+
16
+ Style/AsciiComments:
17
+ Exclude:
18
+ - 'lib/**/*'
19
+ - 'spec/**/*'
20
+
21
+ Style/Documentation:
22
+ Exclude:
23
+ - 'lib/**/*'
24
+ - 'spec/**/*'
25
+
26
+ Style/RaiseArgs:
27
+ Exclude:
28
+ - 'lib/**/*'
29
+
30
+ Style/SpecialGlobalVars:
31
+ Exclude:
32
+ - 'lib/**/*'
33
+ - 'spec/**/*'
34
+
35
+ Style/MultilineBlockChain:
36
+ Exclude:
37
+ - 'lib/**/*'
38
+ - 'spec/**/*'
39
+
40
+ Metrics/ClassLength:
41
+ Max: 200
42
+
43
+ Metrics/CyclomaticComplexity:
44
+ Max: 20
45
+
46
+ Metrics/LineLength:
47
+ Max: 180
48
+
49
+ Metrics/MethodLength:
50
+ Max: 42
51
+
52
+ Metrics/PerceivedComplexity:
53
+ Max: 20
@@ -0,0 +1,33 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-05-03 10:45:53 +0200 using RuboCop version 0.39.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: MinBodyLength.
11
+ Style/GuardClause:
12
+ Exclude:
13
+ - 'lib/emiler.rb'
14
+
15
+ # Offense count: 1
16
+ # Cop supports --auto-correct.
17
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
18
+ # SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
19
+ Style/HashSyntax:
20
+ Enabled: false
21
+
22
+ # Offense count: 1
23
+ # Cop supports --auto-correct.
24
+ Style/MutableConstant:
25
+ Exclude:
26
+ - 'lib/emiler/version.rb'
27
+
28
+ # Offense count: 6
29
+ # Cop supports --auto-correct.
30
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
31
+ # SupportedStyles: single_quotes, double_quotes
32
+ Style/StringLiterals:
33
+ Enabled: false
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.8
4
+ - 2.2.0
5
+ - 2.3.0
6
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at aleksei.matiushkin@kantox.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in emiler.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Aleksei Matiushkin
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.
@@ -0,0 +1,44 @@
1
+ # Emiler
2
+
3
+ Naïve distance calculation for emails. Returns “similar” basing on artificial
4
+ name and domain comparison. [![Build Status](https://travis-ci.org/am-kantox/emiler.svg?branch=master)](https://travis-ci.org/am-kantox/emiler)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'emiler'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install emiler
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'emiler'
26
+
27
+ Emiler.similarity('abc.zzzzzz@example.com', 'abc@example.ru')
28
+ #⇒ {:jw=>0.6897546897546897, :full=>0.8000000000000002, :name=>0.8, :domain=>0.8, :result=>true}
29
+ ```
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/emiler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+
4
+ require 'bundler'
5
+ require 'bundler/setup'
6
+ require 'bundler/gem_tasks'
7
+
8
+ require 'rspec/core/rake_task'
9
+
10
+ begin
11
+ Bundler.setup(:default, :development, :test)
12
+ rescue Bundler::BundlerError => e
13
+ $stderr.puts e.message
14
+ $stderr.puts 'Run `bundle install` to install missing gems'
15
+ exit e.status_code
16
+ end
17
+
18
+ desc 'Tests'
19
+ RSpec::Core::RakeTask.new(:spec) do |spec|
20
+ spec.rspec_opts = '-Ispec'
21
+ # spec.rcov = true
22
+ end
23
+
24
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "emiler"
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
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'emiler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'emiler'
8
+ spec.version = Emiler::VERSION
9
+ spec.authors = ['Aleksei Matiushkin']
10
+ spec.email = ['aleksei.matiushkin@kantox.com']
11
+
12
+ spec.summary = 'Calculates the distance between two emails.'
13
+ spec.description = 'This library is kinda analogue of Jaro-Winkler distance between two emails.'
14
+ spec.homepage = 'https://kantox.com'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.bindir = 'bin'
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.11'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'pry', '~> 0.10'
31
+
32
+ spec.add_dependency 'fuzzy-string-match', '~> 0.9'
33
+ end
@@ -0,0 +1,65 @@
1
+ require 'emiler/version'
2
+ require 'fuzzystringmatch'
3
+
4
+ module Emiler
5
+ USE_PURE = ENV['USE_PURE_JW']
6
+ INEXACT_MATCH_COEFFICIENT = ENV['INEXACT_MATCH_COEFFICIENT'] || 0.8
7
+ RAISE_ON_MALFORMED_EMAIL = ENV['RAISE_ON_MALFORMED_EMAIL']
8
+
9
+ class JW
10
+ attr_reader :jw
11
+ def initialize matcher = :native
12
+ @jw = FuzzyStringMatch::JaroWinkler.create(matcher)
13
+ end
14
+
15
+ def distance s1, s2
16
+ @jw.getDistance s1, s2
17
+ end
18
+
19
+ NATIVE = JW.new
20
+ PURE = USE_PURE ? JW.new(:pure) : nil
21
+ MATCHER = PURE || NATIVE
22
+ DUMMY = { jw: 0, full: 0, name: 0, domain: 0, result: false }.freeze
23
+
24
+ private :initialize
25
+ end
26
+
27
+ class MalformedEmailError < StandardError
28
+ def initialize e1, e2
29
+ super "Rejected to calculate distance for malformed emails <#{e1}>, <#{e2}> due to RAISE_ON_MALFORMED_EMAIL setting"
30
+ end
31
+ end
32
+
33
+ # rubocop:disable Metrics/AbcSize
34
+ def similarity e1, e2
35
+ e1, e2 = [e1, e2].map(&:downcase)
36
+ em1, em2 = [e1, e2].map { |e| e.split '@' }
37
+
38
+ if em1.size != 2 || em2.size != 2
39
+ raise MalformedEmailError.new(e1, e2) if RAISE_ON_MALFORMED_EMAIL
40
+ return JW::DUMMY
41
+ end
42
+
43
+ jw = JW::MATCHER.distance e1, e2
44
+
45
+ domain = case
46
+ when em1.last == em2.last then 1 # exact domain match
47
+ when [em1, em2].map { |e| e.last.split('.')[-2] }.reduce(:==) then INEXACT_MATCH_COEFFICIENT
48
+ else INEXACT_MATCH_COEFFICIENT / 2.0 * JW::MATCHER.distance(em1.last, em2.last)
49
+ end
50
+
51
+ name = case
52
+ when em1.first == em2.first then 1 # exact match
53
+ when ![em1, em2].map { |e| e.first.scan(/[a-z]+/) }.reduce(:&).empty? then INEXACT_MATCH_COEFFICIENT
54
+ else INEXACT_MATCH_COEFFICIENT / 2.0 * JW::MATCHER.distance(em1.first, em2.first)
55
+ end
56
+
57
+ full = domain * 0.2 + name * 0.8
58
+
59
+ { jw: jw, full: full, name: name, domain: domain, result: full >= 0.64 }
60
+ end
61
+ # rubocop:enable Metrics/AbcSize
62
+
63
+ private_constant :JW, :MalformedEmailError
64
+ module_function :similarity
65
+ end
@@ -0,0 +1,3 @@
1
+ module Emiler
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleksei Matiushkin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fuzzy-string-match
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ description: This library is kinda analogue of Jaro-Winkler distance between two emails.
84
+ email:
85
+ - aleksei.matiushkin@kantox.com
86
+ executables:
87
+ - console
88
+ - setup
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - ".rubocop_todo.yml"
96
+ - ".travis.yml"
97
+ - CODE_OF_CONDUCT.md
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - emiler.gemspec
105
+ - lib/emiler.rb
106
+ - lib/emiler/version.rb
107
+ homepage: https://kantox.com
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.8
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Calculates the distance between two emails.
131
+ test_files: []