Skip to content

Commit

Permalink
Refactor and format code
Browse files Browse the repository at this point in the history
- Seperate module and CLI logic
- Parse CLI options using 'optparse'
- Use 'tate' 1.6.0 or above
  • Loading branch information
krmbzds committed Aug 13, 2020
1 parent 64f0219 commit cdb25d4
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.3.0
ruby-2.7.1
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
language: ruby
rvm:
- 2.2.3
- 2.3.0
before_install: gem install bundler -v 1.11.2
- 2.7.1
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in guessmail.gemspec
Expand Down
51 changes: 39 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Guessmail
# Guessmail 💌

[![Travis](https://img.shields.io/travis/krmbzds/guessmail.svg)](https://travis-ci.org/krmbzds/guessmail)
[![Gem](https://img.shields.io/gem/dt/guessmail.svg)](https://rubygems.org/gems/guessmail)
[![Gem](https://img.shields.io/gem/v/guessmail.svg)](https://rubygems.org/gems/guessmail)

**guessmail** helps you find possible email addresses of a person.
[**guessmail**][Guessmail] helps you find possible email addresses of a person.

## Usage

```
Usage: guessmail first [middle] last domain
Examples
guessmail Yukihiro Matz Matsumoto ruby-lang.org
guessmail Satoshi Nakamoto gmx.de
Usage: guessmail [-e] [-l LANGUAGE] first [middle] last domain
-e, --extended Include less common email combinations
-l, --language LANGUAGE Set language
-h, --help Shows help message
-v, --version Shows version
```

## Examples
Expand All @@ -33,7 +33,7 @@ [email protected]
[email protected]
[email protected]
[email protected]
[email protected] <-- This is his email address by the way
[email protected] <-- This is the actual email address
[email protected]
[email protected]
[email protected]
Expand All @@ -47,7 +47,15 @@ [email protected]
[email protected]
```

You can then use an email verifier service or use other methods to find out which one of these email addresses belong to the person you are searching for. Let's not get into that here.
You can then use an email verifier service or use other methods to find out which one of these email addresses belong to the person you are searching for.

[guessmail][Guessmail] can transliterate non-ASCII input since it uses [tate][tate] under the hood. Try it out!

```sh
guessmail Игорь Богданов lex.bg -el bg
guessmail Günter Außem gmx.de --language de
guessmail Yukihiro Matz Matsumoto ruby-lang.org
```

## Is it any good?

Expand All @@ -73,15 +81,34 @@ Or install it yourself as:
$ gem install guessmail
```

## Development

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.

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][RubyGems].

## Contributing

1. Fork it (https://github.com/krmbzds/guessmail/fork)
1. [Fork the repository][Fork]
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

### Donations ❤️

You can donate me at [Liberapay][Donation]. Thanks! ☕️

## License

The MIT License (MIT)
Copyright (c) 2016 Kerem Bozdas
Copyright © 2016-2020 [Kerem Bozdas][Personal Webpage]

This project is available under the terms of the [MIT License][License].

[Donation]: https://liberapay.com/krmbzds/donate
[Fork]: https://github.com/krmbzds/guessmail/fork
[Guessmail]: https://github.com/krmbzds/guessmail
[License]: http://kerem.mit-license.org
[Personal Webpage]: http://kerembozdas.com
[RubyGems]: https://rubygems.org
[Tate]: https://github.com/krmbzds/tate
8 changes: 5 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
7 changes: 4 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "guessmail"
require 'bundler/setup'
require 'guessmail'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +11,5 @@ require "guessmail"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start
55 changes: 29 additions & 26 deletions bin/guessmail
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
#!/usr/bin/env ruby
# encoding: UTF-8
# frozen_string_literal: true

lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)

require 'tate'
require 'templates'
require 'guessmail'
require 'optparse'

@help = '
Usage: guessmail first [middle] last domain
options = {}

Examples
guessmail Yukihiro Matz Matsumoto ruby-lang.org
guessmail Satoshi Nakamoto gmx.de
'
option_parser = OptionParser.new do |opts|
opts.banner = 'Usage: guessmail [-e] [-l LANGUAGE] first [middle] last domain'
opts.on('-e', '--extended', 'Include less common email combinations') do
options[:extended] = true
end
opts.on('-l LANGUAGE', '--language LANGUAGE', String, 'Set language') do |language|
options[:language] = language
end
opts.on('-h', '--help', 'Shows help message') do
options[:help] = opts.help
end
opts.on('-v', '--version', 'Shows version') do
options[:version] = Guessmail::VERSION
end
end

def main
args = ARGV.map { |x| Tate.transliterate(x.downcase) } # tate'd
option_parser.parse!

case args.length
when 3
fn, ln = args.values_at(0, 1)
fi, li = fn[0], ln[0]
dn = args[2]
STDOUT.write $FL % {fn: fn, ln: ln, fi: fi, li: li, dn: dn}
when 4
fn, mn, ln = args.values_at(0, 1, 2)
fi, mi, li = fn[0], mn[0], ln[0]
dn = args[3]
STDOUT.write $FML % {fn: fn, mn: mn, ln: ln, fi: fi, mi: mi, li: li, dn: dn}
result =
if options[:help]
options[:help]
elsif options[:version]
options[:version]
elsif [3, 4].include? ARGV.size
Guessmail.guess(ARGV, options)
else
STDOUT.write @help
option_parser.help
end
end

main
STDOUT.write result
27 changes: 14 additions & 13 deletions guessmail.gemspec
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'guessmail/version'

Gem::Specification.new do |spec|
spec.name = "guessmail"
spec.name = 'guessmail'
spec.version = Guessmail::VERSION
spec.authors = ["Kerem Bozdas"]
spec.email = ["[email protected]"]
spec.authors = ['Kerem Bozdas']
spec.email = ['[email protected]']

spec.summary = "Find anyone's email address"
spec.description = "Find anyone's email address"
spec.homepage = "https://github.com/krmbzds/guessmail"
spec.homepage = 'https://github.com/krmbzds/guessmail'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "bin"
spec.executables = ["guessmail"]
spec.require_paths = ["lib"]
spec.bindir = 'bin'
spec.executables = ['guessmail']
spec.require_paths = ['lib']

spec.add_runtime_dependency "tate", "~> 0.1.4"
spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_runtime_dependency 'tate', '~> 1.6.0'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec'
end
85 changes: 0 additions & 85 deletions lib/extravagant.rb

This file was deleted.

24 changes: 22 additions & 2 deletions lib/guessmail.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
require "guessmail/version"
# frozen_string_literal: true

lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)

require 'guessmail/version'
require 'tate'
require 'templates'

module Guessmail
# I do nothing
def self.guess(names, options)
names.map!(&:downcase)

dn = names.pop
fn = names.shift
ln = names.pop
mn = names.pop

params = { fn: fn, mn: mn, ln: ln, fi: fn[0], mi: (mn[0] if mn), li: ln[0], dn: dn }
template = options[:extended] ? (mn ? FMLE : FLE) : (mn ? FL : FML)
string = format(template, params)

Tate.transliterate(string, options[:language])
end
end
4 changes: 3 additions & 1 deletion lib/guessmail/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Guessmail
VERSION = "0.1.2"
VERSION = '0.1.2'
end
Loading

0 comments on commit cdb25d4

Please sign in to comment.