fantasy_faker 0.2.0 → 0.4.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/CHANGELOG.md +13 -0
- data/README.md +94 -1
- data/lib/fantasy_faker/location.rb +28 -0
- data/lib/fantasy_faker/unique_generator.rb +39 -0
- data/lib/fantasy_faker/utils/base_module.rb +4 -0
- data/lib/fantasy_faker/version.rb +1 -1
- data/lib/fantasy_faker.rb +2 -0
- data/locales/common.yml +1003 -0
- data/locales/en/location.yml +158 -0
- data/locales/pl/location.yml +158 -0
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f0049ad8d6fbde0f3813c16ade4afca229428ad9ab6754914de5a98ae640114
|
|
4
|
+
data.tar.gz: e66524a426cc3c357511a4537cfbd5b4da7c01b8bb69cd8eda43a07b4c5050c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a62d8cbbad60bc9bf5b8e0f868b218d42d57d7ced05cdbb36b701cfdfc310d4ae2796cd2f8f0825e5b72f1484a5863757c95310ecbb5f2fc983ee1c8fd86e610
|
|
7
|
+
data.tar.gz: 9b25c3b7dc00ddff98d867aece0bda0274db9469766064bb241922fcf1e184103cef7d028b411e234939e62d423ac2979838b4e41e1137921d5b9e3d136f35de
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0 - November 11, 2026
|
|
4
|
+
|
|
5
|
+
- Add `FantasyFaker::Location` with 16 location categories and a general-purpose `.name` generator.
|
|
6
|
+
- Add a shared pool of 1,000 invented location names, with English and Polish landmark templates and dark fantasy prefixes and suffixes.
|
|
7
|
+
- Share location `.unique` history across all categories, `.name`, and locales, reserving the proper name regardless of decorative variants; keep character uniqueness unchanged.
|
|
8
|
+
- Add `FantasyFaker::Location.unique.clear` to reset the shared location history.
|
|
9
|
+
|
|
10
|
+
## 0.3.0 - October 24, 2026
|
|
11
|
+
|
|
12
|
+
- Add `.unique` to all character name and nickname generators, with per-method tracking across locale changes.
|
|
13
|
+
- Raise `FantasyFaker::UniqueGenerator::RetryLimitExceeded` after 10,000 unsuccessful attempts to generate a new value.
|
|
14
|
+
- Add `FantasyFaker::Character.unique.clear` to reset uniqueness tracking.
|
|
15
|
+
|
|
3
16
|
## 0.2.0 - October 21, 2026
|
|
4
17
|
|
|
5
18
|
- Expand the first-name dictionaries from 2,499 to 5,040 distinct male names and from 1,380 to 2,795 distinct female names.
|
data/README.md
CHANGED
|
@@ -50,13 +50,106 @@ FantasyFaker.use_locale(:pl) do
|
|
|
50
50
|
end
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### Locations
|
|
54
|
+
|
|
55
|
+
`FantasyFaker::Location` uses a shared pool of 1,000 invented proper names across
|
|
56
|
+
16 categories, with English (`:en`) and Polish (`:pl`) landmark descriptions:
|
|
57
|
+
|
|
58
|
+
Cities return the proper name alone. Other categories combine it with a localized
|
|
59
|
+
landmark type and optional prefixes or suffixes, mixing neutral and dark fantasy styles:
|
|
60
|
+
`Alador Forest`, `Dark Alador Forest`, `Las Alador` or `Puszcza Alador Czarnych Cierni`.
|
|
61
|
+
Proper names are shared between locales; changing language changes the description,
|
|
62
|
+
not the underlying proper-name pool.
|
|
63
|
+
|
|
64
|
+
| Method | Category |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `city` | Cities |
|
|
67
|
+
| `sewer` | Urban sewers |
|
|
68
|
+
| `meadow` | Meadows and wetlands |
|
|
69
|
+
| `forest` | Forests |
|
|
70
|
+
| `swamp` | Swamps |
|
|
71
|
+
| `waters` | Rivers and lakes |
|
|
72
|
+
| `desert` | Deserts and dunes |
|
|
73
|
+
| `cave` | Caves |
|
|
74
|
+
| `mine` | Mines |
|
|
75
|
+
| `mountain` | Mountains |
|
|
76
|
+
| `volcanic_field` | Volcanic fields |
|
|
77
|
+
| `ruins` | Ruins |
|
|
78
|
+
| `stronghold` | Strongholds |
|
|
79
|
+
| `graveyard` | Graveyards |
|
|
80
|
+
| `abandoned_monastery` | Abandoned monasteries |
|
|
81
|
+
| `labyrinth_or_arena` | Labyrinths and arenas |
|
|
82
|
+
|
|
83
|
+
Use `name` to choose a random category and generate a name from it:
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
FantasyFaker::Location.city # => "Alador"
|
|
87
|
+
FantasyFaker::Location.forest # => "Dark Alador Forest"
|
|
88
|
+
FantasyFaker::Location.name # => a name from any location category
|
|
89
|
+
|
|
90
|
+
FantasyFaker.use_locale(:pl) do
|
|
91
|
+
FantasyFaker::Location.city # => "Alador"
|
|
92
|
+
FantasyFaker::Location.forest # => "Mroczny Las Alador"
|
|
93
|
+
FantasyFaker::Location.waters # => "Jezioro Alador Zatopionych Dzwonów"
|
|
94
|
+
end
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Unique values
|
|
98
|
+
|
|
99
|
+
Use `.unique` with any character or location generator.
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
FantasyFaker::Character.unique.male_name
|
|
103
|
+
FantasyFaker::Character.unique.female_nickname
|
|
104
|
+
FantasyFaker::Location.unique.city
|
|
105
|
+
FantasyFaker::Location.unique.name
|
|
106
|
+
|
|
107
|
+
# Reset all character generators' uniqueness history (for example, between tests)
|
|
108
|
+
FantasyFaker::Character.unique.clear
|
|
109
|
+
|
|
110
|
+
# Location history is separate from character history
|
|
111
|
+
FantasyFaker::Location.unique.clear
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
In FactoryBot (formerly FactoryGirl), use it inside the attribute block:
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
factory :character do
|
|
118
|
+
name { FantasyFaker::Character.unique.male_name }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
factory :location do
|
|
122
|
+
name { FantasyFaker::Location.unique.forest }
|
|
123
|
+
end
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Character generators track values separately for each method. Location generators share
|
|
127
|
+
one proper-name history across **all categories, `.name`, and both locales**. For example,
|
|
128
|
+
after `.unique.city` returns `Alador`, no other unique location generator can return
|
|
129
|
+
`Las Alador`, `Dark Alador Forest` or any other variant containing that proper name.
|
|
130
|
+
Prefixes and suffixes do not count as new proper names.
|
|
131
|
+
|
|
132
|
+
Character and location histories are separate. Ordinary calls without `.unique` are not
|
|
133
|
+
tracked and can still reuse names. Tracking happens within the current Ruby process;
|
|
134
|
+
it does not check existing database records or coordinate separate processes.
|
|
135
|
+
|
|
136
|
+
If no new value is found after 10,000 attempts, generation raises
|
|
137
|
+
`FantasyFaker::UniqueGenerator::RetryLimitExceeded` rather than returning a duplicate.
|
|
138
|
+
Because generation is random, this can happen before every possible value has been used.
|
|
139
|
+
The shared location pool contains 1,000 proper names in total, not 1,000 per category
|
|
140
|
+
or language. Use `FantasyFaker::Location.unique.clear` between tests when names can be reused;
|
|
141
|
+
this resets the history for all location categories at once.
|
|
142
|
+
|
|
53
143
|
## Development
|
|
54
144
|
|
|
55
145
|
Dictionary data is stored in YAML files under `locales/`:
|
|
56
|
-
- `locales/common.yml`: language-independent
|
|
146
|
+
- `locales/common.yml`: language-independent character name components (`character:`) and location proper names (`location:`)
|
|
57
147
|
- `locales/en/<module>.yml`: English entries for a module
|
|
58
148
|
- `locales/pl/<module>.yml`: Polish entries for a module
|
|
59
149
|
|
|
150
|
+
Location locale files contain templates with a single `%{name}` placeholder, including
|
|
151
|
+
neutral landmark types and dark fantasy prefixes and suffixes.
|
|
152
|
+
|
|
60
153
|
```sh
|
|
61
154
|
bundle install
|
|
62
155
|
bundle exec rspec
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FantasyFaker
|
|
4
|
+
module Location
|
|
5
|
+
extend BaseModule
|
|
6
|
+
extend self
|
|
7
|
+
|
|
8
|
+
CATEGORIES = %i[
|
|
9
|
+
city sewer meadow forest swamp waters desert cave mine mountain volcanic_field
|
|
10
|
+
ruins stronghold graveyard abandoned_monastery labyrinth_or_arena
|
|
11
|
+
].freeze
|
|
12
|
+
|
|
13
|
+
CATEGORIES.each do |category|
|
|
14
|
+
define_method(category) { fetch_data(category).rand % { name: fetch_data(:proper_names).rand } }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def unique
|
|
18
|
+
@unique_generator ||= begin
|
|
19
|
+
proper_name = /\b#{Regexp.union(fetch_data(:proper_names))}\b/
|
|
20
|
+
UniqueGenerator.new(self) { |name| name[proper_name] }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def name
|
|
25
|
+
public_send(CATEGORIES.sample)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'set'
|
|
4
|
+
|
|
5
|
+
module FantasyFaker
|
|
6
|
+
class UniqueGenerator
|
|
7
|
+
class RetryLimitExceeded < RuntimeError; end
|
|
8
|
+
|
|
9
|
+
def initialize(generator, &key)
|
|
10
|
+
@generator = generator
|
|
11
|
+
@key = key
|
|
12
|
+
@previous_results = Hash.new { |results, method| results[method] = Set.new }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def clear
|
|
16
|
+
@previous_results.clear
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def method_missing(method, ...)
|
|
22
|
+
return super unless @generator.respond_to?(method)
|
|
23
|
+
|
|
24
|
+
# Custom keys identify values across methods, not within one method.
|
|
25
|
+
previous_results = @previous_results[@key ? nil : method]
|
|
26
|
+
10_000.times do
|
|
27
|
+
result = @generator.public_send(method, ...)
|
|
28
|
+
key = @key ? @key.call(result) : result
|
|
29
|
+
return result if previous_results.add?(key)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
raise RetryLimitExceeded, "Unable to generate a unique #{method} after 10,000 attempts"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def respond_to_missing?(method, include_private = false)
|
|
36
|
+
@generator.respond_to?(method) || super
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/fantasy_faker.rb
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'fantasy_faker/version'
|
|
4
4
|
require_relative 'fantasy_faker/utils/array_utils'
|
|
5
|
+
require_relative 'fantasy_faker/unique_generator'
|
|
5
6
|
require_relative 'fantasy_faker/utils/base_module'
|
|
6
7
|
require_relative 'fantasy_faker/character'
|
|
8
|
+
require_relative 'fantasy_faker/location'
|
|
7
9
|
|
|
8
10
|
module FantasyFaker
|
|
9
11
|
DEFAULT_LOCALE = :en
|