genebrand 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +20 -12
- data/Rakefile +4 -4
- data/exe/genebrand +1 -1
- data/genebrand.gemspec +1 -1
- data/lib/genebrand/commands/new.rb +10 -5
- data/lib/genebrand/generator.rb +101 -76
- data/lib/genebrand/posparser.rb +19 -20
- data/lib/genebrand/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46d12688311439cc6f87889a4de0fd957a88c0e2
|
4
|
+
data.tar.gz: ec085f97ad2dae418f50c73969cd12f18bd083c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ca1f24cbc8157fd7ba8e0fc0e2f1167eddacebea69ac007ac1bf6f5ce0a4048aee3d9fe1292e84d9386b6ed79bc25fd5d22bde8bc7c6fb36ef609c1d11a7f99
|
7
|
+
data.tar.gz: 7ba12960fbc7becf1683314fd90e0855a378aad0abe868df369d882d27db5fc067d904efd7a894663383459224affaeeb8aff789214b20f64f73cbaed72950d1
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
# Genebrand
|
2
|
-
|
3
1
|
[](https://codeclimate.com/github/andreyviktorov/genebrand)
|
2
|
+
[](http://inch-ci.org/github/andreyviktorov/genebrand)
|
3
|
+
|
4
|
+
# Genebrand
|
4
5
|
|
5
|
-
CLI brand names generator
|
6
|
+
CLI brand names generator with auto domain availability check
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -24,21 +25,28 @@ And then execute:
|
|
24
25
|
|
25
26
|
And follow instructions
|
26
27
|
|
27
|
-
##
|
28
|
+
## Features
|
28
29
|
|
29
|
-
|
30
|
+
* Whois
|
31
|
+
* Easy to use filters
|
32
|
+
* Several word packs
|
30
33
|
|
34
|
+
## Donate
|
31
35
|
|
32
|
-
|
36
|
+
Support further development with donation
|
33
37
|
|
34
|
-
|
38
|
+
Bitcoin:
|
35
39
|
|
36
|
-
|
40
|
+
**1EoaB8uSnXEfgE3XUZafNs8aETEqdRppku**
|
37
41
|
|
38
|
-
|
42
|
+
Yandex.Money:
|
43
|
+
|
44
|
+
**410013115721646**
|
45
|
+
|
46
|
+
## Contributing
|
39
47
|
|
40
|
-
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/andreyviktorov/genebrand. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
41
49
|
|
42
|
-
|
50
|
+
## License
|
43
51
|
|
44
|
-
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -17,14 +17,14 @@ end
|
|
17
17
|
|
18
18
|
task :seed do
|
19
19
|
require './lib/genebrand/posparser.rb'
|
20
|
-
puts
|
21
|
-
puts
|
20
|
+
puts 'May (and will) take a while'
|
21
|
+
puts 'Parsing all data'
|
22
22
|
parser = Genebrand::PosParser.new
|
23
23
|
parser.parseandsave('seed/preseed.txt', 'lib/data/posinfo.json')
|
24
24
|
|
25
|
-
puts
|
25
|
+
puts 'Parsing with top 100k'
|
26
26
|
parser.parseandsave_top('seed/preseed.txt', 'seed/100k.txt', 'lib/data/pos100k.json')
|
27
27
|
|
28
|
-
puts
|
28
|
+
puts 'Parsing with top 10k'
|
29
29
|
parser.parseandsave_top('seed/preseed.txt', 'seed/10k.txt', 'lib/data/pos10k.json')
|
30
30
|
end
|
data/exe/genebrand
CHANGED
data/genebrand.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = 'Genebrand is a small brands generator'
|
13
13
|
spec.description = 'CLI brand names generator'
|
14
|
-
spec.homepage = 'https://github.com/
|
14
|
+
spec.homepage = 'https://github.com/4ndv/genebrand'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
@@ -37,22 +37,27 @@ module Genebrand
|
|
37
37
|
menu.prompt = 'What should we add?'.yellow
|
38
38
|
|
39
39
|
menu.choice('String') do
|
40
|
-
|
41
|
-
|
42
|
-
q.validate = /\A[a-zA-Z\d]{1,10}\z/
|
43
|
-
end
|
40
|
+
str = { type: :word, word: ask('Enter word (English, no spaces and punctiation, 1-10 symbols)') { |q| q.validate = /\A[a-zA-Z\d]{1,10}\z/ } }
|
41
|
+
brand.push(str)
|
44
42
|
puts
|
45
43
|
end
|
46
44
|
|
47
45
|
menu.choice('Specific part of speech') { brand.push(pickpart) }
|
48
46
|
|
49
|
-
if brand.length >
|
47
|
+
if brand.length > 0
|
50
48
|
menu.choice('Enough, show me some brands!') { throw :parts_done }
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
54
|
+
choose do |menu|
|
55
|
+
menu.prompt = 'Check domain availability?'.yellow
|
56
|
+
|
57
|
+
menu.choice('Yes')
|
58
|
+
menu.choice('No') { @gen.nowhois = true }
|
59
|
+
end
|
60
|
+
|
56
61
|
@gen.generate(brand)
|
57
62
|
end
|
58
63
|
|
data/lib/genebrand/generator.rb
CHANGED
@@ -3,133 +3,158 @@ module Genebrand
|
|
3
3
|
require 'resolv'
|
4
4
|
|
5
5
|
attr_reader :words
|
6
|
+
attr_accessor :nowhois
|
6
7
|
|
7
8
|
def initialize(filename)
|
8
9
|
@words = JSON.parse(File.read(File.join(Gem::Specification.find_by_name('genebrand').gem_dir, "lib/data/#{filename}")))
|
10
|
+
@filtername = {
|
11
|
+
minlen: 'Minimum length:',
|
12
|
+
maxlen: 'Maximum length:',
|
13
|
+
starts: 'Starts with:',
|
14
|
+
ends: 'Ends with:',
|
15
|
+
contains: 'Contains:'
|
16
|
+
}
|
9
17
|
end
|
10
18
|
|
11
|
-
def
|
12
|
-
data = '['
|
13
|
-
|
14
|
-
# A bit hacky, but pretty fast method to guess domain available or not
|
19
|
+
def is_available?(domain, zone)
|
15
20
|
resolv = Resolv::DNS.open
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
data
|
21
|
-
|
21
|
+
resolv.getresources("#{domain}.#{zone}", Resolv::DNS::Resource::IN::NS).count == 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def prettyoutput(domain)
|
25
|
+
data = ''
|
26
|
+
unless @nowhois
|
27
|
+
# A bit hacky, but pretty fast method to guess domain available or not
|
28
|
+
resolv = Resolv::DNS.open
|
29
|
+
com = is_available?(domain, 'com') ? 'com'.green : 'com'.red
|
30
|
+
net = is_available?(domain, 'net') ? 'net'.green : 'net'.red
|
31
|
+
org = is_available?(domain, 'org') ? 'org'.green : 'org'.red
|
32
|
+
data = "[#{com} #{net} #{org}]\t"
|
33
|
+
end
|
22
34
|
data << domain.bold
|
23
35
|
|
24
|
-
|
36
|
+
data
|
25
37
|
end
|
26
38
|
|
27
|
-
def
|
28
|
-
out = []
|
29
|
-
|
39
|
+
def getinfo(info)
|
30
40
|
puts
|
31
41
|
puts 'Generating brands with these parameters:'.cyan
|
32
42
|
puts
|
33
|
-
i =
|
43
|
+
i = 0
|
34
44
|
|
35
45
|
info.each do |item|
|
36
46
|
if item[:type] == :word
|
37
|
-
puts "#{i}. Word: #{item[:word]}".green
|
47
|
+
puts "#{i += 1}. Word: #{item[:word]}".green
|
38
48
|
elsif item[:type] == :part
|
39
|
-
puts "#{i}. Part of speech: #{item[:part]}".green
|
49
|
+
puts "#{i += 1}. Part of speech: #{item[:part]}".green
|
40
50
|
puts 'Filters:'
|
41
|
-
item[:filters].each do |filter,
|
42
|
-
|
43
|
-
puts "Minimum length: #{value}"
|
44
|
-
elsif filter == :maxlen
|
45
|
-
puts "Maximum length: #{value}"
|
46
|
-
elsif filter == :starts
|
47
|
-
puts "Starts with: #{value}"
|
48
|
-
elsif filter == :ends
|
49
|
-
puts "Ends with: #{value}"
|
50
|
-
elsif filter == :contains
|
51
|
-
puts "Contains: #{value}"
|
52
|
-
end
|
51
|
+
item[:filters].each do |filter, _value|
|
52
|
+
puts "#{@filtername[filter]} #{_value}"
|
53
53
|
end
|
54
54
|
end
|
55
|
+
end
|
56
|
+
end
|
55
57
|
|
56
|
-
|
58
|
+
def filter(parts, filter, value)
|
59
|
+
case filter
|
60
|
+
when :minlen
|
61
|
+
parts = parts.select { |i| i[/^.{#{value},}$/] }
|
62
|
+
when :maxlen
|
63
|
+
parts = parts.select { |i| i[/^.{,#{value}}$/] }
|
64
|
+
when :starts
|
65
|
+
parts = parts.select { |i| i[/^#{value}.*$/i] }
|
66
|
+
when :ends
|
67
|
+
parts = parts.select { |i| i[/^.*#{value}$/i] }
|
68
|
+
when :contains
|
69
|
+
parts = parts.select { |i| i[/^.*(#{value}).*$/i] }
|
57
70
|
end
|
71
|
+
parts
|
72
|
+
end
|
58
73
|
|
59
|
-
|
60
|
-
|
61
|
-
|
74
|
+
def applyfilters(item)
|
75
|
+
parts = @words[item[:part]]
|
76
|
+
item[:filters].each do |filter, value|
|
77
|
+
parts = filter(parts, filter, value)
|
78
|
+
end
|
62
79
|
|
63
|
-
|
80
|
+
parts
|
81
|
+
end
|
82
|
+
|
83
|
+
def prepareparts(info)
|
64
84
|
gener = []
|
65
|
-
|
85
|
+
puts 'Fetching variants...'
|
66
86
|
info.each do |item|
|
67
87
|
if item[:type] == :word
|
68
|
-
wordscount += 1
|
69
88
|
gener.push(item[:word])
|
70
89
|
elsif item[:type] == :part
|
71
|
-
parts =
|
72
|
-
item[:filters].each do |filter, value|
|
73
|
-
if filter == :minlen
|
74
|
-
parts = parts.select { |i| i[/^.{#{value},}$/] }
|
75
|
-
elsif filter == :maxlen
|
76
|
-
parts = parts.select { |i| i[/^.{,#{value}}$/] }
|
77
|
-
elsif filter == :starts
|
78
|
-
parts = parts.select { |i| i[/^#{value}.*$/i] }
|
79
|
-
elsif filter == :ends
|
80
|
-
parts = parts.select { |i| i[/^.*#{value}$/i] }
|
81
|
-
elsif filter == :contains
|
82
|
-
parts = parts.select { |i| i[/^.*(#{value}).*$/i] }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
90
|
+
parts = applyfilters(item)
|
86
91
|
if parts.count > 0
|
87
92
|
gener.push(parts)
|
88
93
|
else
|
89
|
-
Genebrand::Logger.warning
|
94
|
+
Genebrand::Logger.warning '0 variants for that part, will be skipped'
|
90
95
|
end
|
91
96
|
end
|
92
97
|
end
|
93
98
|
|
94
|
-
|
99
|
+
gener
|
100
|
+
end
|
95
101
|
|
96
|
-
|
102
|
+
def generateone(gener)
|
103
|
+
itemd = ''
|
104
|
+
|
105
|
+
gener.each_with_index do |item, index|
|
97
106
|
if item.is_a? Array
|
98
|
-
|
107
|
+
ind = rand(gener[index].count)
|
108
|
+
itemd << gener[index][ind].capitalize
|
109
|
+
else
|
110
|
+
itemd << gener[index].capitalize
|
99
111
|
end
|
100
112
|
end
|
101
113
|
|
102
|
-
|
103
|
-
|
104
|
-
puts 'Available variants: '.yellow + approx.to_s.bold
|
105
|
-
puts
|
106
|
-
|
107
|
-
puts "Whois info\tBrand"
|
114
|
+
itemd
|
115
|
+
end
|
108
116
|
|
109
|
-
|
117
|
+
def proceedgen(gener)
|
110
118
|
i = 0
|
111
|
-
|
112
|
-
itemd =
|
113
|
-
|
114
|
-
gener.each_with_index do |item, index|
|
115
|
-
if item.is_a? Array
|
116
|
-
ind = rand(gener[index].count)
|
117
|
-
itemd << gener[index][ind].capitalize
|
118
|
-
else
|
119
|
-
itemd << gener[index].capitalize
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
119
|
+
loop do
|
120
|
+
itemd = generateone(gener)
|
123
121
|
puts prettyoutput(itemd)
|
124
122
|
|
125
123
|
i += 1
|
126
124
|
|
127
|
-
if i%15 == 0
|
125
|
+
if i % 15 == 0
|
128
126
|
puts
|
129
|
-
puts
|
127
|
+
puts 'Press any key to see next variants'.cyan
|
130
128
|
gets
|
131
129
|
end
|
132
130
|
end
|
133
131
|
end
|
132
|
+
|
133
|
+
def countvariants(gener)
|
134
|
+
approx = 1
|
135
|
+
|
136
|
+
gener.each do |item|
|
137
|
+
approx *= item.count if item.is_a? Array
|
138
|
+
end
|
139
|
+
|
140
|
+
puts 'Available variants: '.yellow + approx.to_s.bold
|
141
|
+
puts
|
142
|
+
end
|
143
|
+
|
144
|
+
def generate(info)
|
145
|
+
getinfo(info)
|
146
|
+
|
147
|
+
gener = prepareparts(info)
|
148
|
+
|
149
|
+
countvariants(gener)
|
150
|
+
|
151
|
+
if @nowhois
|
152
|
+
puts 'Brand'
|
153
|
+
else
|
154
|
+
puts "Whois info\tBrand"
|
155
|
+
end
|
156
|
+
|
157
|
+
proceedgen(gener)
|
158
|
+
end
|
134
159
|
end
|
135
160
|
end
|
data/lib/genebrand/posparser.rb
CHANGED
@@ -3,11 +3,8 @@ module Genebrand
|
|
3
3
|
require 'json'
|
4
4
|
require 'fileutils'
|
5
5
|
|
6
|
+
# Fills parts of speech table
|
6
7
|
def initialize
|
7
|
-
init
|
8
|
-
end
|
9
|
-
|
10
|
-
def init
|
11
8
|
@parsed = {}
|
12
9
|
@table = {}
|
13
10
|
# Сущ
|
@@ -22,6 +19,10 @@ module Genebrand
|
|
22
19
|
@table['A'] = @parsed['adj'] = []
|
23
20
|
end
|
24
21
|
|
22
|
+
# Parses file of word\tpartofspeech
|
23
|
+
#
|
24
|
+
# @param [String] filename that should be parsed
|
25
|
+
# @return [Hash] of partofspeech => words
|
25
26
|
def parse(filename)
|
26
27
|
init
|
27
28
|
|
@@ -30,18 +31,22 @@ module Genebrand
|
|
30
31
|
return
|
31
32
|
end
|
32
33
|
|
33
|
-
puts
|
34
|
+
puts 'Seeding'
|
34
35
|
File.open(filename, 'r').each_line do |line|
|
35
36
|
data = line.split("\t")
|
36
37
|
|
37
|
-
data
|
38
|
-
@table[partofsp].push(data[0].downcase) if @table.key?(partofsp)
|
39
|
-
end
|
38
|
+
getparts(data)
|
40
39
|
end
|
41
40
|
|
42
41
|
@parsed
|
43
42
|
end
|
44
43
|
|
44
|
+
def getparts(data)
|
45
|
+
data[1].split('').each do |partofsp|
|
46
|
+
@table[partofsp].push(data[0].downcase) if @table.key?(partofsp)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
45
50
|
def parse_top(filename, top)
|
46
51
|
init
|
47
52
|
|
@@ -50,27 +55,21 @@ module Genebrand
|
|
50
55
|
return
|
51
56
|
end
|
52
57
|
|
53
|
-
puts
|
58
|
+
puts 'Load top'
|
54
59
|
toparr = []
|
55
60
|
File.open(top, 'r').each_line do |line|
|
56
61
|
toparr << line.strip.downcase
|
57
62
|
end
|
58
63
|
puts toparr.count
|
59
64
|
|
60
|
-
puts
|
65
|
+
puts 'Seeding'
|
61
66
|
it = 0
|
62
67
|
File.open(filename, 'r').each_line do |line|
|
63
68
|
data = line.split("\t")
|
64
69
|
|
65
|
-
if toparr.include?(data[0])
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
it+=1
|
71
|
-
if it % 10000 == 0
|
72
|
-
puts it
|
73
|
-
end
|
70
|
+
getparts(data) if toparr.include?(data[0])
|
71
|
+
it += 1
|
72
|
+
puts it if it % 10_000 == 0
|
74
73
|
end
|
75
74
|
|
76
75
|
@parsed
|
@@ -86,7 +85,7 @@ module Genebrand
|
|
86
85
|
return
|
87
86
|
end
|
88
87
|
|
89
|
-
puts
|
88
|
+
puts 'Preseed'
|
90
89
|
File.open(filename, 'r').each_line do |line|
|
91
90
|
data = line.split("\t")
|
92
91
|
|
data/lib/genebrand/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genebrand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Viktorov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorator
|
@@ -109,7 +109,7 @@ files:
|
|
109
109
|
- lib/genebrand/logger.rb
|
110
110
|
- lib/genebrand/posparser.rb
|
111
111
|
- lib/genebrand/version.rb
|
112
|
-
homepage: https://github.com/
|
112
|
+
homepage: https://github.com/4ndv/genebrand
|
113
113
|
licenses:
|
114
114
|
- MIT
|
115
115
|
metadata:
|