rubyrt 1.0.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 +7 -0
- data/bin/rubyrt +4 -0
- data/lib/rubyrt.rb +61 -0
- data/words_alpha_dwyl_infochimps.txt +370105 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aef49f9bf2618c9903157eb7036e7666c5736d6b07d6174c098a426cb151ff2b
|
4
|
+
data.tar.gz: caaa0dd1d42ae45588f30a86c58754c3a67f5b0b228b27fed9a7dd1779b2a8a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e21298a0e17b8441685a9a3fcb8095941467c12ba56a8095d77e2d9e9e1dff1545f9babc7a3d7c92ab6381fbc0167d42c59a7c02b1d553887c7ef0704c27216
|
7
|
+
data.tar.gz: e3593dbe406ec077a0b96275a1525f12c8fb657d4e1e55b81d3189e64f8f8a6f2c67e126e0346001c38ae16503e11fe316221ae65c742a2518b6bf1687bac9b3
|
data/bin/rubyrt
ADDED
data/lib/rubyrt.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# lib/rubyrt.rb
|
2
|
+
|
3
|
+
module Rubyrt
|
4
|
+
VERSION='1.0.1'
|
5
|
+
|
6
|
+
class << self
|
7
|
+
require 'optparse'
|
8
|
+
$options = {}
|
9
|
+
|
10
|
+
parser = OptionParser.new do |parser|
|
11
|
+
parser.on("-c", "--capitalize", "Capitalize the First letter")
|
12
|
+
parser.on("-d", "--divider DIVIDER_CHARACTER", "Separating character between words")
|
13
|
+
parser.on("-f","--file WORDLIST_FILE", "The wordlist used for generation")
|
14
|
+
parser.on("-h", "--help", "Print this message") do
|
15
|
+
puts parser
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
parser.on("-l", "--length LENGTH", "The length of the generated name as a number")
|
19
|
+
parser.on("-r", "--random", "Use a random length from 1-4")
|
20
|
+
parser.on("-s", "--size WORD_SIZE", "The size in characters of the allowed words")
|
21
|
+
end
|
22
|
+
|
23
|
+
parser.parse!(into:$options)
|
24
|
+
|
25
|
+
# Function to pick a random line in a file
|
26
|
+
def pick_line(file, word_length)
|
27
|
+
file ||= File.join(File.dirname(__dir__), "words_alpha_dwyl_infochimps.txt")
|
28
|
+
# "words_alpha_dwyl_infochimps.txt"
|
29
|
+
word_length ||= 10
|
30
|
+
word_length = word_length.to_i
|
31
|
+
chosen_line = nil
|
32
|
+
|
33
|
+
100.times do
|
34
|
+
File.foreach(file.to_s).each_with_index do |line, number|
|
35
|
+
chosen_line = line if rand <1.0/(number + 1)
|
36
|
+
end
|
37
|
+
break if chosen_line.length <= word_length
|
38
|
+
end
|
39
|
+
puts "No word at length " + word_length.to_s + " found in 100 tries" if chosen_line.length > word_length
|
40
|
+
|
41
|
+
# Determine the capitalization behavior
|
42
|
+
unless $options.key?(:capitalize)
|
43
|
+
return chosen_line
|
44
|
+
end
|
45
|
+
return chosen_line.capitalize.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def lengthening
|
49
|
+
output = ""
|
50
|
+
|
51
|
+
# For the size of length
|
52
|
+
length = $options.key?(:length) ? $options.fetch(:length) : 1 + rand(3)
|
53
|
+
length.to_i.times do
|
54
|
+
# If divider is present; use it.
|
55
|
+
output += pick_line(($options.fetch(:file) if $options.key?(:file)), ($options.fetch(:size) if $options.key?(:size))).chomp() + ($options.key?(:divider) ? $options.fetch(:divider).to_s : "")
|
56
|
+
end
|
57
|
+
# Get the length of the optional divider and remove its length from the end of the string. | Removes appended divider
|
58
|
+
return output[0..-($options.key?(:divider) ? $options.fetch(:divider).length + 1 : 1)]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|