story-gen 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/NEWS +3 -0
  2. data/lib/once.rb +5 -0
  3. data/lib/unique_names.rb +20 -7
  4. metadata +3 -2
data/NEWS CHANGED
@@ -1,3 +1,6 @@
1
+ 0.1.5:
2
+ Add "once" and "UniqueNames.delete"
3
+
1
4
  0.1.3:
2
5
  Bug fixes
3
6
 
@@ -0,0 +1,5 @@
1
+
2
+ # You can use +redo+ inside the passed block.
3
+ def once
4
+ break yield while true
5
+ end
@@ -1,6 +1,8 @@
1
1
  # encoding: UTF-8
2
+ require 'set'
3
+ require 'once'
2
4
 
3
- # Infinite array of unique names.
5
+ # Infinite set of unique names.
4
6
  class UniqueNames
5
7
 
6
8
  # @param [Array<String>] base_names base names which will be used to
@@ -8,7 +10,8 @@ class UniqueNames
8
10
  def initialize(base_names)
9
11
  @base_names = base_names
10
12
  @postfix_id = 0
11
- reinit_current_names
13
+ @deleted_names = Set.new
14
+ reinit_current_names()
12
15
  end
13
16
 
14
17
  # @return [UniqueNames]
@@ -243,14 +246,24 @@ class UniqueNames
243
246
  UniqueNames.new ["Olivia", "Grace", "Ruby", "Jessica", "Emily", "Sophie", "Chloe", "Lucy", "Lily", "Ella", "Ellie", "Amelia", "Charlotte", "Katie", "Mia", "Hannah", "Evie", "Megan", "Amy", "Isabella", "Millie", "Isabelle", "Abigail", "Freya", "Molly", "Daisy", "Holly", "Emma", "Erin", "Poppy", "Jasmine", "Phoebe", "Leah", "Keira", "Caitlin", "Imogen", "Madison", "Rebecca", "Elizabeth", "Georgia", "Sophia", "Lauren", "Scarlett", "Amber", "Ava", "Eleanor", "Bethany", "Alice", "Isabel", "Summer", "Paige", "Anna", "Lola", "Libby", "Eva", "Maisie", "Isobel", "Brooke", "Lilly", "Alisha", "Tia", "Sarah", "Amelie", "Gracie", "Faith", "Rosie", "Courtney", "Matilda", "Niamh", "Maddison", "Sienna", "Eve", "Aimee", "Skye", "Zara", "Isla", "Shannon", "Madeleine", "Harriet", "Zoe", "Nicole", "Sofia", "Abbie", "Maya", "Lacey", "Rachel", "Francesca", "Layla", "Lydia", "Alicia", "Hollie", "Martha", "Alexandra", "Julia", "Natasha", "Lexie", "Mollie", "Morgan", "Maria", "Demi", "Rose", "Laura", "Lara", "Victoria", "Tilly", "Sara", "Evelyn", "Eloise"]
244
247
  end
245
248
 
249
+ # @param [String] name
250
+ # @return [self]
251
+ def delete(name)
252
+ @deleted_names.add name
253
+ return self
254
+ end
255
+
246
256
  # @return [String]
247
257
  def pop
248
- n = @current_names.pop + postfix
249
- if @current_names.empty?
250
- @postfix_id += 1
251
- reinit_current_names
258
+ once do
259
+ n = @current_names.pop + postfix
260
+ if @current_names.empty?
261
+ @postfix_id += 1
262
+ reinit_current_names
263
+ end
264
+ redo if @deleted_names.include? n
265
+ return n
252
266
  end
253
- return n
254
267
  end
255
268
 
256
269
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: story-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-25 00:00:00.000000000 Z
12
+ date: 2016-02-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Generate stories from descriptions based on Facts!
15
15
  email: various.furriness@gmail.com
@@ -18,6 +18,7 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - lib/once.rb
21
22
  - lib/strscan/substr.rb
22
23
  - lib/any.rb
23
24
  - lib/fact.rb