dunmanifestin 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dunmanifestin +2 -0
- data/default-genre/root.pal +10 -0
- data/lib/dunmanifestin/array.rb +16 -0
- data/lib/dunmanifestin/palette.rb +6 -3
- data/lib/dunmanifestin/phrase.rb +6 -5
- data/lib/dunmanifestin/terminator.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55d7067a0c40ad1e14de97d12e9b8a3244e07d0852823b242227686fa37279d6
|
4
|
+
data.tar.gz: 3207afa67b6f493fcd4feefb934acba148a347428b1d67b10c142c559172e99a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0d1c2fe81d1bb8d4c71a48cb7e788cc2718217f0f5cc63552d6908b98235b51d0c2df61427561abc00ce648eff9ec598f5fe1beed891cca318f0843cb48902f
|
7
|
+
data.tar.gz: f68a590e1ad6848f0ded1a08c7a4c34e80d26d5e44b2fdf402acadeee97e5f372caabc82e34b0edb4c9aa4f0a028fa2f771acd46a7437aeb1bbce7a58b4adf01
|
data/bin/dunmanifestin
CHANGED
@@ -12,6 +12,8 @@ user_demands = Optimist::options do
|
|
12
12
|
opt :phrase, "Specify a phrase or list, e.g. 'The [animal] sat on the [article]' or '[weapon]'", type: :string, short: '-p'
|
13
13
|
opt :chomp, "remove the trailing newline from the output", short: '-o'
|
14
14
|
opt :file, "Read a file as the phrase", type: :string, short: '-f'
|
15
|
+
opt :coarse_seed, "Stick to one region", type: :integer, short: "-s"
|
16
|
+
opt :fine_seed, "Lock all randomness", type: :integer, short: "-e"
|
15
17
|
end
|
16
18
|
|
17
19
|
begin
|
data/default-genre/root.pal
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
NUM_DEFAULT_REGIONS = 100000
|
2
|
+
RECCURENCES = 5
|
3
|
+
COARSE_SEED ||= rand(NUM_DEFAULT_REGIONS)
|
4
|
+
FINE_SEED ||= nil
|
5
|
+
|
6
|
+
META_RANDOM = FINE_SEED ? Random.new(FINE_SEED) : Random.new
|
7
|
+
RANDOMS = RECCURENCES.times.map { Random.new(COARSE_SEED) }
|
8
|
+
|
9
|
+
class Array
|
10
|
+
def constrained_sample(randoms: RANDOMS, meta_random: META_RANDOM)
|
11
|
+
self.sample(
|
12
|
+
1,
|
13
|
+
random: randoms.sample(1, random: meta_random).pop
|
14
|
+
).pop
|
15
|
+
end
|
16
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
class Palette
|
2
2
|
GAP_BETWEEN_LISTS = /\n(?=\|)/
|
3
3
|
PALETTE_TITLE = /^\|(.*?)\n/
|
4
|
+
COMMENT = /\/\/(.*?)\n/
|
4
5
|
class << self
|
5
6
|
def expose path
|
6
7
|
File.open(path).read
|
7
8
|
.split(GAP_BETWEEN_LISTS)
|
8
9
|
.each &method(:expose_swatches)
|
9
10
|
end
|
10
|
-
|
11
|
+
|
11
12
|
def expose_swatches body
|
13
|
+
body.gsub!(COMMENT, '')
|
12
14
|
list_name = body.match(PALETTE_TITLE)[1].to_s
|
13
15
|
|
14
16
|
if list_name.empty?
|
@@ -25,8 +27,9 @@ class Palette
|
|
25
27
|
qlass = declare_phrase_class list_name
|
26
28
|
# Where is 'list' defined?
|
27
29
|
qlass.list body
|
30
|
+
rescue NoMethodError
|
28
31
|
end
|
29
|
-
|
32
|
+
|
30
33
|
def declare_phrase_class list_name
|
31
34
|
name = list_name.underscore.camelize
|
32
35
|
qlass = "Phrase::#{name}".constantize
|
@@ -36,4 +39,4 @@ class Palette
|
|
36
39
|
Phrase.const_set name, qlass
|
37
40
|
end
|
38
41
|
end
|
39
|
-
end
|
42
|
+
end
|
data/lib/dunmanifestin/phrase.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
2
|
require_relative 'custom_inflections'
|
3
|
+
require_relative 'array'
|
3
4
|
|
4
5
|
class Phrase
|
5
6
|
def self.list new_list = nil, multiline_document = false
|
6
|
-
return (@list ||
|
7
|
+
return (@list || List.new) unless new_list
|
7
8
|
|
8
9
|
new_list = new_list.split_on_newlines_and_strip if new_list.is_a?(String) unless multiline_document
|
9
10
|
new_list = [new_list] if multiline_document
|
@@ -18,7 +19,7 @@ class Phrase
|
|
18
19
|
@list = new_list
|
19
20
|
end
|
20
21
|
|
21
|
-
def initialize dsl_string = self.class.list.
|
22
|
+
def initialize dsl_string = self.class.list.constrained_sample
|
22
23
|
raise "Try again." unless dsl_string
|
23
24
|
compile parse dsl_string
|
24
25
|
end
|
@@ -132,13 +133,13 @@ class Phrase
|
|
132
133
|
return self unless @inflection_delegates
|
133
134
|
self.instance_variable_set("@#{inflection}", true)
|
134
135
|
return (titleize! && self) if inflection == :titleize
|
135
|
-
|
136
|
+
|
136
137
|
delegates = @inflection_delegates[inflection]
|
137
138
|
delegates.each { |delegate| variables[delegate].inflect inflection }
|
138
|
-
|
139
|
+
|
139
140
|
self
|
140
141
|
end
|
141
|
-
|
142
|
+
|
142
143
|
def to_s
|
143
144
|
render_inflections @to_s_proc.call
|
144
145
|
end
|
@@ -9,6 +9,9 @@ class Terminator
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def address demands
|
12
|
+
$coarse_seed = demands[:coarse_seed] || $coarse_seed
|
13
|
+
$fine_seed = demands[:fine_seed] || $fine_seed
|
14
|
+
|
12
15
|
phrase_string = phrasing(demands[:phrase], demands[:file])
|
13
16
|
root_phrase_class = Class.new(Phrase) { list phrase_string, !!demands[:file] }
|
14
17
|
list_loader.load demands[:genre]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dunmanifestin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- quavmo
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-04-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- default-genre/superlative.pal
|
98
98
|
- default-genre/verb.pal
|
99
99
|
- lib/dunmanifestin.rb
|
100
|
+
- lib/dunmanifestin/array.rb
|
100
101
|
- lib/dunmanifestin/custom_inflections.rb
|
101
102
|
- lib/dunmanifestin/generator.rb
|
102
103
|
- lib/dunmanifestin/list.rb
|