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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aafdf33e0c1bd0eed164e68e866a36831f9eccd6b7e64e949d7cdb1bfa83a1ec
4
- data.tar.gz: e346a4848f4dbc9e3c4943ea5fc9fd688dfcc9a6998dd988bd17a1445fd11b70
3
+ metadata.gz: 55d7067a0c40ad1e14de97d12e9b8a3244e07d0852823b242227686fa37279d6
4
+ data.tar.gz: 3207afa67b6f493fcd4feefb934acba148a347428b1d67b10c142c559172e99a
5
5
  SHA512:
6
- metadata.gz: c1c96d88f550b14aa0d3832fd9a608d722ee3700d98e55846b19f35748406196d3722b613cd554ca0b36fbc65abecff7a43bcaf8a94b5eeaa97c57a15ed4ad74
7
- data.tar.gz: 78e0cf762ca0ea6e6ac53291c8ee7eaf84d1ab13d174b27c4c49bcd65623933cf58551d72f4c627cacfacedea773ddf8d5abdb09ed7bd605c441ace9b97ac409
6
+ metadata.gz: c0d1c2fe81d1bb8d4c71a48cb7e788cc2718217f0f5cc63552d6908b98235b51d0c2df61427561abc00ce648eff9ec598f5fe1beed891cca318f0843cb48902f
7
+ data.tar.gz: f68a590e1ad6848f0ded1a08c7a4c34e80d26d5e44b2fdf402acadeee97e5f372caabc82e34b0edb4c9aa4f0a028fa2f771acd46a7437aeb1bbce7a58b4adf01
@@ -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
@@ -184,3 +184,13 @@ won't
184
184
  |timerange
185
185
  never
186
186
  always
187
+
188
+ |animal
189
+ dog
190
+ cat
191
+ dove
192
+ turtle
193
+ fox
194
+ wolf
195
+ fish
196
+ worm
@@ -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
@@ -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 || []) unless new_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.sample
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.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-03-30 00:00:00.000000000 Z
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