poefy 1.0.0 → 1.1.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/.gitignore +0 -3
- data/README.md +73 -34
- data/bin/poefy +44 -7
- data/bin/poefy_make +6 -8
- data/lib/poefy/core_extensions/array.rb +18 -0
- data/lib/poefy/database.rb +1 -3
- data/lib/poefy/db_type.rb +7 -14
- data/lib/poefy/exceptions.rb +123 -0
- data/lib/poefy/generation.rb +29 -11
- data/lib/poefy/poem_base.rb +112 -112
- data/lib/poefy/poetic_forms.rb +529 -367
- data/lib/poefy/string_manipulation.rb +0 -14
- data/lib/poefy/version.rb +2 -2
- data/lib/poefy.rb +1 -2
- data/settings.yml +2 -0
- data/spec/poefy_unit_spec.rb +455 -33
- metadata +4 -3
- data/lib/poefy/handle_error.rb +0 -35
@@ -114,20 +114,6 @@ module Poefy
|
|
114
114
|
text
|
115
115
|
end
|
116
116
|
|
117
|
-
# Convert each element in an input array to Integer, and raise
|
118
|
-
# an error if the conversion is not possible for any element.
|
119
|
-
def each_to_int input_array, error_to_raise = TypeError
|
120
|
-
output_array = []
|
121
|
-
input_array.each do |elem|
|
122
|
-
begin
|
123
|
-
output_array << Integer(elem)
|
124
|
-
rescue ArgumentError => e
|
125
|
-
raise error_to_raise
|
126
|
-
end
|
127
|
-
end
|
128
|
-
output_array
|
129
|
-
end
|
130
|
-
|
131
117
|
# Combine two hashes together, transforming all values to array.
|
132
118
|
# These arrays are then flattened.
|
133
119
|
def merge_hashes one, two
|
data/lib/poefy/version.rb
CHANGED
data/lib/poefy.rb
CHANGED
@@ -21,7 +21,7 @@ require_relative 'poefy/generation.rb'
|
|
21
21
|
require_relative 'poefy/poetic_forms.rb'
|
22
22
|
require_relative 'poefy/poetic_form_from_text.rb'
|
23
23
|
require_relative 'poefy/string_manipulation.rb'
|
24
|
-
require_relative 'poefy/
|
24
|
+
require_relative 'poefy/exceptions.rb'
|
25
25
|
require_relative 'poefy/database.rb'
|
26
26
|
require_relative 'poefy/conditional_sample.rb'
|
27
27
|
require_relative 'poefy/core_extensions/array.rb'
|
@@ -38,7 +38,6 @@ module Poefy
|
|
38
38
|
include Poefy::PoeticFormFromText
|
39
39
|
include Poefy::StringManipulation
|
40
40
|
include Poefy::ConditionalSample
|
41
|
-
include Poefy::HandleError
|
42
41
|
|
43
42
|
end
|
44
43
|
|
data/settings.yml
ADDED
data/spec/poefy_unit_spec.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
describe Poefy::Poem, "-- Unit tests" do
|
7
7
|
|
8
|
-
describe "#
|
8
|
+
describe "#transform_input_regex" do
|
9
9
|
|
10
10
|
# Singleton which includes the method.
|
11
11
|
# Make the private methods public.
|
@@ -18,7 +18,47 @@ describe Poefy::Poem, "-- Unit tests" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "using rhyme string 'aabba'" do
|
21
|
-
|
21
|
+
normal_input = [
|
22
|
+
[/^T/,
|
23
|
+
{
|
24
|
+
1=>/^T/,
|
25
|
+
2=>/^T/,
|
26
|
+
3=>/^T/,
|
27
|
+
4=>/^T/,
|
28
|
+
5=>/^T/
|
29
|
+
}],
|
30
|
+
[/^T/i,
|
31
|
+
{
|
32
|
+
1=>/^T/i,
|
33
|
+
2=>/^T/i,
|
34
|
+
3=>/^T/i,
|
35
|
+
4=>/^T/i,
|
36
|
+
5=>/^T/i
|
37
|
+
}],
|
38
|
+
['rgegerg',
|
39
|
+
{
|
40
|
+
1=>/rgegerg/,
|
41
|
+
2=>/rgegerg/,
|
42
|
+
3=>/rgegerg/,
|
43
|
+
4=>/rgegerg/,
|
44
|
+
5=>/rgegerg/
|
45
|
+
}],
|
46
|
+
['^[A-Z]',
|
47
|
+
{
|
48
|
+
1=>/^[A-Z]/,
|
49
|
+
2=>/^[A-Z]/,
|
50
|
+
3=>/^[A-Z]/,
|
51
|
+
4=>/^[A-Z]/,
|
52
|
+
5=>/^[A-Z]/
|
53
|
+
}],
|
54
|
+
['[A-Z]',
|
55
|
+
{
|
56
|
+
1=>/[A-Z]/,
|
57
|
+
2=>/[A-Z]/,
|
58
|
+
3=>/[A-Z]/,
|
59
|
+
4=>/[A-Z]/,
|
60
|
+
5=>/[A-Z]/
|
61
|
+
}],
|
22
62
|
['^[^e]*$',
|
23
63
|
{
|
24
64
|
1=>/^[^e]*$/,
|
@@ -27,7 +67,79 @@ describe Poefy::Poem, "-- Unit tests" do
|
|
27
67
|
4=>/^[^e]*$/,
|
28
68
|
5=>/^[^e]*$/
|
29
69
|
}],
|
30
|
-
[
|
70
|
+
[[/a/,/b/,/c/,/d/,/e/],
|
71
|
+
{
|
72
|
+
1=>/a/,
|
73
|
+
2=>/b/,
|
74
|
+
3=>/c/,
|
75
|
+
4=>/d/,
|
76
|
+
5=>/e/
|
77
|
+
}],
|
78
|
+
[['a','b','c','d','e'],
|
79
|
+
{
|
80
|
+
1=>/a/,
|
81
|
+
2=>/b/,
|
82
|
+
3=>/c/,
|
83
|
+
4=>/d/,
|
84
|
+
5=>/e/
|
85
|
+
}],
|
86
|
+
[['a',/b/,'c',/d/,/e/],
|
87
|
+
{
|
88
|
+
1=>/a/,
|
89
|
+
2=>/b/,
|
90
|
+
3=>/c/,
|
91
|
+
4=>/d/,
|
92
|
+
5=>/e/
|
93
|
+
}],
|
94
|
+
[[/a/,/b/,/c/,/d/,/e/],
|
95
|
+
{
|
96
|
+
1=>/a/,
|
97
|
+
2=>/b/,
|
98
|
+
3=>/c/,
|
99
|
+
4=>/d/,
|
100
|
+
5=>/e/
|
101
|
+
}],
|
102
|
+
[{1=>'a', 2=>'b', 3=>'c', 4=>'d', 5=>'e'},
|
103
|
+
{
|
104
|
+
1=>/a/,
|
105
|
+
2=>/b/,
|
106
|
+
3=>/c/,
|
107
|
+
4=>/d/,
|
108
|
+
5=>/e/
|
109
|
+
}],
|
110
|
+
[{1=>/a/, 2=>/b/, 3=>/c/, 4=>/d/, 5=>/e/},
|
111
|
+
{
|
112
|
+
1=>/a/,
|
113
|
+
2=>/b/,
|
114
|
+
3=>/c/,
|
115
|
+
4=>/d/,
|
116
|
+
5=>/e/
|
117
|
+
}],
|
118
|
+
[{1=>/a/, 2=>'b', 3=>'c', 4=>/d/, 5=>/e/},
|
119
|
+
{
|
120
|
+
1=>/a/,
|
121
|
+
2=>/b/,
|
122
|
+
3=>/c/,
|
123
|
+
4=>/d/,
|
124
|
+
5=>/e/
|
125
|
+
}],
|
126
|
+
[{0=>/o/, 3=>'c', 4=>/d/},
|
127
|
+
{
|
128
|
+
1=>/o/,
|
129
|
+
2=>/o/,
|
130
|
+
3=>/c/,
|
131
|
+
4=>/d/,
|
132
|
+
5=>/o/
|
133
|
+
}],
|
134
|
+
["['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']",
|
135
|
+
{
|
136
|
+
1=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
|
137
|
+
2=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
|
138
|
+
3=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
|
139
|
+
4=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
|
140
|
+
5=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/
|
141
|
+
}],
|
142
|
+
[['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$'],
|
31
143
|
{
|
32
144
|
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
33
145
|
2=>/^[^eE]*$/,
|
@@ -35,7 +147,7 @@ describe Poefy::Poem, "-- Unit tests" do
|
|
35
147
|
4=>/^[^eE]*$/,
|
36
148
|
5=>/^[^eE]*$/
|
37
149
|
}],
|
38
|
-
[
|
150
|
+
["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', 4: '^[^eE]*$', 5: '^[^eE]*$'}",
|
39
151
|
{
|
40
152
|
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
41
153
|
2=>/^[^eE]*$/,
|
@@ -43,7 +155,7 @@ describe Poefy::Poem, "-- Unit tests" do
|
|
43
155
|
4=>/^[^eE]*$/,
|
44
156
|
5=>/^[^eE]*$/
|
45
157
|
}],
|
46
|
-
[
|
158
|
+
[{1=>'(?=^[A-Z])(?=^[^eE]*$)', 2=>'^[^eE]*$', 3=>'^[^eE]*$', 4=>'^[^eE]*$', 5=>'^[^eE]*$'},
|
47
159
|
{
|
48
160
|
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
49
161
|
2=>/^[^eE]*$/,
|
@@ -51,38 +163,178 @@ describe Poefy::Poem, "-- Unit tests" do
|
|
51
163
|
4=>/^[^eE]*$/,
|
52
164
|
5=>/^[^eE]*$/
|
53
165
|
}],
|
54
|
-
[
|
166
|
+
[{1=>/(?=^[A-Z])(?=^[^eE]*$)/, 2=>'^[^eE]*$', 3=>'^[^eE]*$', 4=>/^[^eE]*$/, 5=>'^[^eE]*$'},
|
55
167
|
{
|
56
168
|
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
57
169
|
2=>/^[^eE]*$/,
|
58
170
|
3=>/^[^eE]*$/,
|
59
|
-
4
|
171
|
+
4=>/^[^eE]*$/,
|
60
172
|
5=>/^[^eE]*$/
|
61
173
|
}],
|
62
|
-
['
|
174
|
+
["{0: '^[^eE]*$', 1: '(?=^[A-Z])(?=^[^eE]*$)'}",
|
63
175
|
{
|
64
176
|
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
65
|
-
2
|
66
|
-
3
|
177
|
+
2=>/^[^eE]*$/,
|
178
|
+
3=>/^[^eE]*$/,
|
67
179
|
4=>/^[^eE]*$/,
|
68
|
-
5
|
180
|
+
5=>/^[^eE]*$/
|
69
181
|
}],
|
70
|
-
['
|
182
|
+
[{0=>'^[^eE]*$', 1=>'(?=^[A-Z])(?=^[^eE]*$)'},
|
71
183
|
{
|
72
184
|
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
73
185
|
2=>/^[^eE]*$/,
|
74
186
|
3=>/^[^eE]*$/,
|
75
187
|
4=>/^[^eE]*$/,
|
76
188
|
5=>/^[^eE]*$/
|
77
|
-
}]
|
189
|
+
}],
|
190
|
+
["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', 5: '^[^eE]*$'}",
|
191
|
+
{
|
192
|
+
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
193
|
+
2=>/^[^eE]*$/,
|
194
|
+
3=>/^[^eE]*$/,
|
195
|
+
4=>//,
|
196
|
+
5=>/^[^eE]*$/
|
197
|
+
}],
|
198
|
+
["{1: '(?=^[A-Z])(?=^[^eE]*$)', 4: '^[^eE]*$'}",
|
199
|
+
{
|
200
|
+
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
201
|
+
2=>//,
|
202
|
+
3=>//,
|
203
|
+
4=>/^[^eE]*$/,
|
204
|
+
5=>//
|
205
|
+
}],
|
206
|
+
["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', -1: '^[^eE]*$', -2: '^[^eE]*$'}",
|
207
|
+
{
|
208
|
+
1=>/(?=^[A-Z])(?=^[^eE]*$)/,
|
209
|
+
2=>/^[^eE]*$/,
|
210
|
+
3=>/^[^eE]*$/,
|
211
|
+
4=>/^[^eE]*$/,
|
212
|
+
5=>/^[^eE]*$/
|
213
|
+
}],
|
214
|
+
['{7: \'^\S+$\'}',
|
215
|
+
{
|
216
|
+
1=>//,
|
217
|
+
2=>//,
|
218
|
+
3=>//,
|
219
|
+
4=>//,
|
220
|
+
5=>//,
|
221
|
+
7=>/^\S+$/
|
222
|
+
}],
|
223
|
+
[{'3m1'=>/a/, 2=>'b', 0=>/c/},
|
224
|
+
{
|
225
|
+
1=>/a/,
|
226
|
+
2=>/b/,
|
227
|
+
3=>/c/,
|
228
|
+
4=>/a/,
|
229
|
+
5=>/c/
|
230
|
+
}],
|
231
|
+
]
|
232
|
+
weird_input = [
|
233
|
+
['x',
|
234
|
+
{ 1=>/x/,
|
235
|
+
2=>/x/,
|
236
|
+
3=>/x/,
|
237
|
+
4=>/x/,
|
238
|
+
5=>/x/
|
239
|
+
}],
|
240
|
+
['xxxx',
|
241
|
+
{ 1=>/xxxx/,
|
242
|
+
2=>/xxxx/,
|
243
|
+
3=>/xxxx/,
|
244
|
+
4=>/xxxx/,
|
245
|
+
5=>/xxxx/
|
246
|
+
}],
|
247
|
+
['xxxx40',
|
248
|
+
{ 1=>/xxxx40/,
|
249
|
+
2=>/xxxx40/,
|
250
|
+
3=>/xxxx40/,
|
251
|
+
4=>/xxxx40/,
|
252
|
+
5=>/xxxx40/
|
253
|
+
}],
|
254
|
+
['xx40xx',
|
255
|
+
{ 1=>/xx40xx/,
|
256
|
+
2=>/xx40xx/,
|
257
|
+
3=>/xx40xx/,
|
258
|
+
4=>/xx40xx/,
|
259
|
+
5=>/xx40xx/
|
260
|
+
}],
|
261
|
+
['<40xxxx></40xxxx>',
|
262
|
+
{ 1=>/<40xxxx><\/40xxxx>/,
|
263
|
+
2=>/<40xxxx><\/40xxxx>/,
|
264
|
+
3=>/<40xxxx><\/40xxxx>/,
|
265
|
+
4=>/<40xxxx><\/40xxxx>/,
|
266
|
+
5=>/<40xxxx><\/40xxxx>/
|
267
|
+
}],
|
268
|
+
['{xxxxx: xxxxx}',
|
269
|
+
{1=>//,2=>//,3=>//,4=>//,5=>//}],
|
270
|
+
['{2: f}',
|
271
|
+
{1=>//,2=>/f/,3=>//,4=>//,5=>//}],
|
272
|
+
[:foo,
|
273
|
+
{1=>/foo/,2=>/foo/,3=>/foo/,4=>/foo/,5=>/foo/}],
|
274
|
+
[{0=>:foo, 4=>:bar},
|
275
|
+
{1=>/foo/,2=>/foo/,3=>/foo/,4=>/bar/,5=>/foo/}],
|
276
|
+
[123,
|
277
|
+
{1=>/123/,2=>/123/,3=>/123/,4=>/123/,5=>/123/}],
|
278
|
+
[Object,
|
279
|
+
{1=>/Object/,2=>/Object/,3=>/Object/,4=>/Object/,5=>/Object/}],
|
280
|
+
[GC,
|
281
|
+
{1=>/GC/,2=>/GC/,3=>/GC/,4=>/GC/,5=>/GC/}],
|
282
|
+
[TypeError.new('foo'),
|
283
|
+
{1=>/foo/,2=>/foo/,3=>/foo/,4=>/foo/,5=>/foo/}],
|
284
|
+
['{xxxxx}',
|
285
|
+
{1=>//,2=>//,3=>//,4=>//,5=>//}],
|
286
|
+
['{{xxxxx}}',
|
287
|
+
{1=>//,2=>//,3=>//,4=>//,5=>//}],
|
288
|
+
['{3: }',
|
289
|
+
{1=>//,2=>//,3=>//,4=>//,5=>//}],
|
290
|
+
['{40}',
|
291
|
+
{1=>//,2=>//,3=>//,4=>//,40=>//,5=>//}],
|
292
|
+
['{[40]}',
|
293
|
+
{1=>//,2=>//,3=>//,4=>//,5=>//}],
|
294
|
+
['{{40}}',
|
295
|
+
{1=>//,2=>//,3=>//,4=>//,5=>//}],
|
296
|
+
['{{}}',
|
297
|
+
{1=>//,2=>//,3=>//,4=>//,5=>//}],
|
298
|
+
['{1: 12',
|
299
|
+
{1=>/{1: 12/,2=>/{1: 12/,3=>/{1: 12/,4=>/{1: 12/,5=>/{1: 12/}],
|
78
300
|
]
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
301
|
+
error_input = [
|
302
|
+
"{1: /(?=^[A-Z])(?=^[^eE]*$)/, 4: /^[^eE]*$/}",
|
303
|
+
'{3: 4: 5}',
|
304
|
+
'{xxxxx: 8000, 0: xxxxx: 8000}',
|
305
|
+
]
|
306
|
+
describe "normal input" do
|
307
|
+
normal_input.each do |pair|
|
308
|
+
it "regex: #{pair.first}" do
|
309
|
+
rhyme = obj.tokenise_rhyme('aabba')
|
310
|
+
out = obj.transform_input_regex(pair.first, 'aabba')
|
311
|
+
again = obj.transform_input_regex(out, 'aabba')
|
312
|
+
expect(out).to eq pair.last
|
313
|
+
expect(again).to eq out
|
314
|
+
expect(again).to eq pair.last
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
describe "weird (but technically fine) input" do
|
319
|
+
weird_input.each do |pair|
|
320
|
+
it "regex: #{pair.first}" do
|
321
|
+
rhyme = obj.tokenise_rhyme('aabba')
|
322
|
+
out = obj.transform_input_regex(pair.first, 'aabba')
|
323
|
+
again = obj.transform_input_regex(out, 'aabba')
|
324
|
+
expect(out).to eq pair.last
|
325
|
+
expect(again).to eq out
|
326
|
+
expect(again).to eq pair.last
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
describe "error input" do
|
331
|
+
error_input.each do |i|
|
332
|
+
it "regex: #{i}" do
|
333
|
+
rhyme = obj.tokenise_rhyme('aabba')
|
334
|
+
expect {
|
335
|
+
obj.transform_input_regex(i, 'aabba')
|
336
|
+
}.to raise_error(Poefy::RegexError)
|
337
|
+
end
|
86
338
|
end
|
87
339
|
end
|
88
340
|
end
|
@@ -90,7 +342,7 @@ describe Poefy::Poem, "-- Unit tests" do
|
|
90
342
|
|
91
343
|
##############################################################################
|
92
344
|
|
93
|
-
describe "#
|
345
|
+
describe "#transform_input_syllable" do
|
94
346
|
|
95
347
|
# Singleton which includes the method.
|
96
348
|
# Make the private methods public.
|
@@ -102,11 +354,23 @@ describe Poefy::Poem, "-- Unit tests" do
|
|
102
354
|
end.new
|
103
355
|
end
|
104
356
|
describe "using rhyme string 'aabba'" do
|
105
|
-
|
357
|
+
normal_input = [
|
358
|
+
[0,
|
359
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
360
|
+
[10,
|
361
|
+
{1=>10,2=>10,3=>10,4=>10,5=>10}],
|
362
|
+
['0',
|
363
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
106
364
|
['10',
|
107
365
|
{1=>10,2=>10,3=>10,4=>10,5=>10}],
|
108
|
-
['
|
109
|
-
{1=>
|
366
|
+
['99',
|
367
|
+
{1=>99,2=>99,3=>99,4=>99,5=>99}],
|
368
|
+
['8,9,10',
|
369
|
+
{1=>[8,9,10],2=>[8,9,10],3=>[8,9,10],4=>[8,9,10],5=>[8,9,10]}],
|
370
|
+
['6,7,8,9',
|
371
|
+
{1=>[6,7,8,9],2=>[6,7,8,9],3=>[6,7,8,9],4=>[6,7,8,9],5=>[6,7,8,9]}],
|
372
|
+
['[10]',
|
373
|
+
{1=>10,2=>0,3=>0,4=>0,5=>0}],
|
110
374
|
['[8,8,5,5,8]',
|
111
375
|
{1=>8,2=>8,3=>5,4=>5,5=>8}],
|
112
376
|
['[[8,9],[8,9],[4,5,6],[4,5,6],[8,9]]',
|
@@ -128,16 +392,174 @@ describe Poefy::Poem, "-- Unit tests" do
|
|
128
392
|
['{1:8,5:8}',
|
129
393
|
{1=>8,2=>0,3=>0,4=>0,5=>8}],
|
130
394
|
['{1:8,2:8,3:5,-2:5,-1:8}',
|
131
|
-
{1=>8,2=>8,3=>5,4=>5,5=>8}]
|
395
|
+
{1=>8,2=>8,3=>5,4=>5,5=>8}],
|
396
|
+
['{o:1,e:2}',
|
397
|
+
{1=>1,2=>2,3=>1,4=>2,5=>1}],
|
398
|
+
['{o:1,0:9}',
|
399
|
+
{1=>1,2=>9,3=>1,4=>9,5=>1}],
|
400
|
+
['{o:1,e:2,0:9}',
|
401
|
+
{1=>1,2=>2,3=>1,4=>2,5=>1}],
|
402
|
+
['{o:8,e:6,-2:6,-1:4}',
|
403
|
+
{1=>8,2=>6,3=>8,4=>6,5=>4}],
|
404
|
+
['{o:8,e:6,-2:6,-1:4,0:9}',
|
405
|
+
{1=>8,2=>6,3=>8,4=>6,5=>4}],
|
406
|
+
['8-10',
|
407
|
+
{1=>[8,9,10],2=>[8,9,10],3=>[8,9,10],4=>[8,9,10],5=>[8,9,10]}],
|
408
|
+
['6-9',
|
409
|
+
{1=>[6,7,8,9],2=>[6,7,8,9],3=>[6,7,8,9],4=>[6,7,8,9],5=>[6,7,8,9]}],
|
410
|
+
['4-9',
|
411
|
+
{ 1=>[4,5,6,7,8,9],
|
412
|
+
2=>[4,5,6,7,8,9],
|
413
|
+
3=>[4,5,6,7,8,9],
|
414
|
+
4=>[4,5,6,7,8,9],
|
415
|
+
5=>[4,5,6,7,8,9]}],
|
416
|
+
['4,6,8-10,12',
|
417
|
+
{ 1=>[4,6,8,9,10,12],
|
418
|
+
2=>[4,6,8,9,10,12],
|
419
|
+
3=>[4,6,8,9,10,12],
|
420
|
+
4=>[4,6,8,9,10,12],
|
421
|
+
5=>[4,6,8,9,10,12]}],
|
422
|
+
['[4,6,8-10,12]',
|
423
|
+
{1=>4,2=>6,3=>[8,9,10],4=>12,5=>0}],
|
424
|
+
['{e:"4,6,8-10,12"}',
|
425
|
+
{1=>0,2=>[4,6,8,9,10,12],3=>0,4=>[4,6,8,9,10,12],5=>0}],
|
426
|
+
['{0:6,-1:6-10}',
|
427
|
+
{1=>6,2=>6,3=>6,4=>6,5=>[6,7,8,9,10]}],
|
428
|
+
['{0:4-6,-1:6-10}',
|
429
|
+
{1=>[4,5,6],2=>[4,5,6],3=>[4,5,6],4=>[4,5,6],5=>[6,7,8,9,10]}],
|
430
|
+
['{e:4-6,-1:6-10}',
|
431
|
+
{1=>0,2=>[4,5,6],3=>0,4=>[4,5,6],5=>[6,7,8,9,10]}],
|
432
|
+
['[[8,9],[8,9],[4,5,6],[4,5,6],[8,9]]',
|
433
|
+
{1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
|
434
|
+
['[[8-9],[8-9],[4-6],[4-6],[8-9]]',
|
435
|
+
{1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
|
436
|
+
['[[8,9],[8,9],4-6,4-6,[8,9]]',
|
437
|
+
{1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
|
438
|
+
['[8-9,8-9,4-6,4-6,8-9]',
|
439
|
+
{1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
|
440
|
+
['{0:11,3m0:30}',
|
441
|
+
{1=>11,2=>11,3=>30,4=>11,5=>11}],
|
442
|
+
['{0:11,3m0:30,3m1:31}',
|
443
|
+
{1=>31,2=>11,3=>30,4=>31,5=>11}],
|
444
|
+
[{0=>11,'3m0'=>30,'3m1'=>31},
|
445
|
+
{1=>31,2=>11,3=>30,4=>31,5=>11}],
|
446
|
+
[{0=>11,'3m0'=>[1,2,3,4],'3m1'=>31},
|
447
|
+
{1=>31,2=>11,3=>[1,2,3,4],4=>31,5=>11}]
|
448
|
+
]
|
449
|
+
weird_input = [
|
450
|
+
['40xxxx',
|
451
|
+
{1=>40,2=>40,3=>40,4=>40,5=>40}],
|
452
|
+
['{3: 4 5}',
|
453
|
+
{1=>0,2=>0,3=>4,4=>0,5=>0}],
|
454
|
+
['{}',
|
455
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
456
|
+
['{xxxxx: 8}',
|
457
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
458
|
+
['{xxxxx: 8000}',
|
459
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
460
|
+
['{2m12: 9}',
|
461
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
462
|
+
['{1m0: 9}',
|
463
|
+
{1=>9,2=>9,3=>9,4=>9,5=>9}],
|
464
|
+
['{1m1: 9}',
|
465
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
466
|
+
['{-1m0: 9}',
|
467
|
+
{1=>9,2=>9,3=>9,4=>9,5=>9}],
|
468
|
+
['{-1m1: 9}',
|
469
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
470
|
+
['{-1m1: -9}',
|
471
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
472
|
+
['{10: 2}',
|
473
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0,10=>2}],
|
474
|
+
['{0:1, 0:2, 0:3, 0:4, 0:5, 0:6, 0:7, 0:8, 0:9}',
|
475
|
+
{1=>9,2=>9,3=>9,4=>9,5=>9}],
|
476
|
+
['{1: -12}',
|
477
|
+
{1=>12,2=>0,3=>0,4=>0,5=>0}],
|
478
|
+
['{-12: -12}',
|
479
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
480
|
+
['1: 12}',
|
481
|
+
{1=>1,2=>1,3=>1,4=>1,5=>1}],
|
482
|
+
['1: 12',
|
483
|
+
{1=>1,2=>1,3=>1,4=>1,5=>1}],
|
484
|
+
['40 ',
|
485
|
+
{1=>40,2=>40,3=>40,4=>40,5=>40}],
|
486
|
+
[' 40',
|
487
|
+
{1=>40,2=>40,3=>40,4=>40,5=>40}],
|
488
|
+
['{1m1: 9} ',
|
489
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
490
|
+
[' {1m1: 9}',
|
491
|
+
{1=>0,2=>0,3=>0,4=>0,5=>0}],
|
492
|
+
['[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,5]]]]]',
|
493
|
+
{1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5]}],
|
494
|
+
['[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,999,[1,2,3,4,5]]]]]',
|
495
|
+
{1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5,999]}],
|
496
|
+
[[10],
|
497
|
+
{1=>10,2=>0,3=>0,4=>0,5=>0}],
|
498
|
+
[[8,8,5,5,8],
|
499
|
+
{1=>8,2=>8,3=>5,4=>5,5=>8}],
|
500
|
+
[[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,999,[1,2,3,4,5]]]]],
|
501
|
+
{1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5,999]}],
|
502
|
+
[3.141592653,
|
503
|
+
{1=>3,2=>3,3=>3,4=>3,5=>3}],
|
504
|
+
[1.618033988,
|
505
|
+
{1=>1,2=>1,3=>1,4=>1,5=>1}]
|
506
|
+
]
|
507
|
+
error_input = [
|
508
|
+
'x',
|
509
|
+
'xxxx',
|
510
|
+
'xxxx40',
|
511
|
+
'xx40xx',
|
512
|
+
'<40xxxx></40xxxx>',
|
513
|
+
'{1: 12',
|
514
|
+
'{xxxxx}',
|
515
|
+
'{{xxxxx}}',
|
516
|
+
'{xxxxx: xxxxx}',
|
517
|
+
'{2: f}',
|
518
|
+
'{3: }',
|
519
|
+
'{3: 4: 5}',
|
520
|
+
'{xxxxx: 8000, 0: xxxxx: 8000}',
|
521
|
+
'{40}',
|
522
|
+
'{[40]}',
|
523
|
+
'{{40}}',
|
524
|
+
'{{}}',
|
525
|
+
:sausage,
|
526
|
+
/^the/,
|
527
|
+
Object,
|
528
|
+
GC,
|
529
|
+
TypeError.new('foo')
|
132
530
|
]
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
531
|
+
describe "normal input" do
|
532
|
+
normal_input.each do |pair|
|
533
|
+
it "syllable: #{pair.first}" do
|
534
|
+
rhyme = obj.tokenise_rhyme('aabba')
|
535
|
+
out = obj.transform_input_syllable(pair.first, 'aabba')
|
536
|
+
again = obj.transform_input_syllable(out, 'aabba')
|
537
|
+
expect(out).to eq pair.last
|
538
|
+
expect(again).to eq out
|
539
|
+
expect(again).to eq pair.last
|
540
|
+
end
|
541
|
+
end
|
542
|
+
end
|
543
|
+
describe "weird (but technically fine) input" do
|
544
|
+
weird_input.each do |pair|
|
545
|
+
it "syllable: #{pair.first}" do
|
546
|
+
rhyme = obj.tokenise_rhyme('aabba')
|
547
|
+
out = obj.transform_input_syllable(pair.first, 'aabba')
|
548
|
+
again = obj.transform_input_syllable(out, 'aabba')
|
549
|
+
expect(out).to eq pair.last
|
550
|
+
expect(again).to eq out
|
551
|
+
expect(again).to eq pair.last
|
552
|
+
end
|
553
|
+
end
|
554
|
+
end
|
555
|
+
describe "error input" do
|
556
|
+
error_input.each do |i|
|
557
|
+
it "syllable: #{i}" do
|
558
|
+
rhyme = obj.tokenise_rhyme('aabba')
|
559
|
+
expect {
|
560
|
+
obj.transform_input_syllable(i, 'aabba')
|
561
|
+
}.to raise_error(Poefy::SyllableError)
|
562
|
+
end
|
141
563
|
end
|
142
564
|
end
|
143
565
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poefy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -190,8 +190,8 @@ files:
|
|
190
190
|
- lib/poefy/core_extensions/array.rb
|
191
191
|
- lib/poefy/database.rb
|
192
192
|
- lib/poefy/db_type.rb
|
193
|
+
- lib/poefy/exceptions.rb
|
193
194
|
- lib/poefy/generation.rb
|
194
|
-
- lib/poefy/handle_error.rb
|
195
195
|
- lib/poefy/poem_base.rb
|
196
196
|
- lib/poefy/poetic_form_from_text.rb
|
197
197
|
- lib/poefy/poetic_forms.rb
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- lib/poefy/string_manipulation.rb
|
200
200
|
- lib/poefy/version.rb
|
201
201
|
- poefy.gemspec
|
202
|
+
- settings.yml
|
202
203
|
- spec/poefy_unit_spec.rb
|
203
204
|
- spec/spec_helper.rb
|
204
205
|
homepage: https://github.com/nossidge/poefy
|