codeobscure 0.1.7.7 → 0.1.8.0
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/lib/codeobscure/obscure.rb +1 -1
- data/lib/codeobscure/version.rb +1 -1
- data/lib/random-word/LICENSE.txt +20 -0
- data/lib/random-word/data/adjs.json +19001 -0
- data/lib/random-word/data/nouns.json +112986 -0
- data/lib/random-word/lib/random-word.rb +1 -0
- data/lib/random-word/lib/random_word.rb +121 -0
- data/lib/random-word/lib/random_word/version.rb +3 -0
- metadata +8 -16
@@ -0,0 +1 @@
|
|
1
|
+
require 'random_word'
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'pathname'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# Provides random, non-repeating enumerators of a large list of
|
6
|
+
# english words. For example"
|
7
|
+
#
|
8
|
+
# RandomWord.adjs.next #=> "strengthened"
|
9
|
+
#
|
10
|
+
module RandomWord
|
11
|
+
module EachRandomly
|
12
|
+
attr_accessor :random_word_exclude_list
|
13
|
+
attr_accessor :min_length
|
14
|
+
attr_accessor :max_length
|
15
|
+
|
16
|
+
def each_randomly(&blk)
|
17
|
+
used = Set.new
|
18
|
+
skipped = Set.new
|
19
|
+
loop do
|
20
|
+
idx = next_unused_idx(used)
|
21
|
+
used << idx
|
22
|
+
word = at(idx)
|
23
|
+
if excluded?(word)
|
24
|
+
skipped << idx
|
25
|
+
next
|
26
|
+
end
|
27
|
+
yield word
|
28
|
+
used.subtract(skipped)
|
29
|
+
skipped.clear
|
30
|
+
end
|
31
|
+
|
32
|
+
rescue OutOfWords
|
33
|
+
# we are done.
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_constraints(opts = {})
|
37
|
+
@min_length = opts[:not_shorter_than] || 1
|
38
|
+
@max_length = opts[:not_longer_than] || Float::INFINITY
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.extended(mod)
|
42
|
+
mod.set_constraints
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def next_unused_idx(used)
|
48
|
+
idx = rand(length)
|
49
|
+
try = 1
|
50
|
+
while used.include?(idx)
|
51
|
+
raise OutOfWords if try > 1000
|
52
|
+
idx = rand(length)
|
53
|
+
try += 1
|
54
|
+
end
|
55
|
+
|
56
|
+
idx
|
57
|
+
end
|
58
|
+
|
59
|
+
def excluded?(word)
|
60
|
+
exclude_list = Array(@random_word_exclude_list)
|
61
|
+
(
|
62
|
+
word.nil? ||
|
63
|
+
exclude_list.any? {|r| r === word} ||
|
64
|
+
word.length < min_length ||
|
65
|
+
(!(max_length.nil?) && word.length > max_length)
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
class OutOfWords < Exception; end
|
70
|
+
end
|
71
|
+
|
72
|
+
class << self
|
73
|
+
attr_accessor :word_list
|
74
|
+
|
75
|
+
def exclude_list
|
76
|
+
@exclude_list ||= []
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [Enumerator] Random noun enumerator
|
80
|
+
def nouns(opts = {})
|
81
|
+
@nouns ||= enumerator(load_word_list("nouns.json"), exclude_list)
|
82
|
+
word_list.set_constraints(opts)
|
83
|
+
@nouns
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Enumerator] Random adjective enumerator
|
87
|
+
def adjs(opts = {})
|
88
|
+
@adjs ||= enumerator(load_word_list("adjs.json"), exclude_list)
|
89
|
+
word_list.set_constraints(opts)
|
90
|
+
@adjs
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [Enumerator] Random phrase enumerator
|
94
|
+
def phrases
|
95
|
+
@phrases ||= (Class.new do
|
96
|
+
def each()
|
97
|
+
while true
|
98
|
+
yield "#{RandomWord.adjs.next} #{RandomWord.nouns.next}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end.new).to_enum
|
102
|
+
end
|
103
|
+
|
104
|
+
# Create a random, non-repeating enumerator for a list of words
|
105
|
+
# (or anything really).
|
106
|
+
def enumerator(word_list, list_of_regexs_or_strings_to_exclude = [])
|
107
|
+
@word_list = word_list
|
108
|
+
word_list.extend EachRandomly
|
109
|
+
word_list.random_word_exclude_list = list_of_regexs_or_strings_to_exclude
|
110
|
+
word_list.enum_for(:each_randomly)
|
111
|
+
end
|
112
|
+
|
113
|
+
protected
|
114
|
+
|
115
|
+
def load_word_list(name)
|
116
|
+
filename = File.join Pathname(File.dirname(__FILE__)), "../data", name
|
117
|
+
JSON.parse(File.read(filename))
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeobscure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.3'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: random-word
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '2.1'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '2.1'
|
111
97
|
description: Code Obscure Tool.You can use it simplely
|
112
98
|
email:
|
113
99
|
- chengkai1853@163.com
|
@@ -125,6 +111,12 @@ files:
|
|
125
111
|
- lib/codeobscure/imagemix.rb
|
126
112
|
- lib/codeobscure/obscure.rb
|
127
113
|
- lib/codeobscure/version.rb
|
114
|
+
- lib/random-word/LICENSE.txt
|
115
|
+
- lib/random-word/data/adjs.json
|
116
|
+
- lib/random-word/data/nouns.json
|
117
|
+
- lib/random-word/lib/random-word.rb
|
118
|
+
- lib/random-word/lib/random_word.rb
|
119
|
+
- lib/random-word/lib/random_word/version.rb
|
128
120
|
- test/codeobscure_test.rb
|
129
121
|
- test/test_helper.rb
|
130
122
|
homepage: https://github.com/kaich/codeobscure
|