eunomia_gen 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef932c7746b729d5ca11965c6f60d51a2bda8d3ea8c3b86ec7ef4920bd3f8d6d
4
- data.tar.gz: c237ff9ef45c99ae42bdd26d95c050f2a888f3c64e4ff58c2f5778e5979be716
3
+ metadata.gz: dda6a6807dc92353a11e090f8d61cbeb238510a8a7a0f6d524e9a90328192317
4
+ data.tar.gz: 0b54749ea476821a8511a355d6ddce2591128bc2417f60f8161d2405120708c4
5
5
  SHA512:
6
- metadata.gz: b5f1be4da9fa2c83d9da04cded7de88e60d53eafc943383c3b1b96a50cdef42d4b35328b1a9cc3d0b300158aa9c3cdac264fb8e62141f711c30725c65d9e94e6
7
- data.tar.gz: b6ac9cfb36380bedad9982c53802b0b3dec9c6d3d9e69e2930e6cf972e8cd685679aff6ef78b1c59c7fc187626282a4d09f2962916173bbcb2dd727c93f8732d
6
+ metadata.gz: b624e0b5f19812df73cacf9bf2abab0d55078f78cf5adc6d50eac078feb6d3bdce34d2e0ba5b2b9bae1d005a7049b971465399dd142b5c29dac876e49a048aa8
7
+ data.tar.gz: ea823e74de17872ec4706c6648319f425e11ec9a25cf6c9581872c942d21af08495aab34e2b47f0c21142c4154759c618f00059b29674dad5196d3c5aa59496b
data/README.md CHANGED
@@ -125,6 +125,33 @@ If the first segment is not a number the multiplier defaults to 1.
125
125
  A constant hash can be added to the request. A string that matches the hash key will be replaced by the
126
126
  constant value.
127
127
 
128
+ ### Tags and Filtering
129
+
130
+ Tags can be used to filter items. For example, some plant names are also used as names. So a list of
131
+ plants could be filtered to only those that are also names to generate a character name. Tags assigned
132
+ to an item are also added as metadat to the result if the tag is in `key:value` format.
133
+
134
+ ```ruby
135
+ data = [
136
+ { key: "plant", items: %w[[flower] [tree]] },
137
+ { key: "flower", items: [
138
+ { segments: "rose", tags: %w[name:plant] },
139
+ { segments: "hydrangea" }
140
+ ]
141
+ },
142
+ { key: "tree", items: [
143
+ { segments: "ash", tags: %w[name:plant] },
144
+ { segments: "oak" }
145
+ ]
146
+ }
147
+ ]
148
+
149
+ Eunomia.add(data)
150
+ val = Eunomia.generate("plant", tags: %w[name:plant], functions: ["capitalize"])
151
+ p val.to_s # => "Rose" or "Ash"
152
+ p val.meta # => { "tag" => "name:plant" }
153
+ ```
154
+
128
155
  ## Development
129
156
 
130
157
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec`
@@ -7,6 +7,7 @@ module Eunomia
7
7
  include Eunomia::HashHelpers
8
8
 
9
9
  attr_reader :key,
10
+ :aliases,
10
11
  :alts,
11
12
  :meta,
12
13
  :functions,
@@ -17,6 +18,7 @@ module Eunomia
17
18
 
18
19
  def initialize(hsh)
19
20
  @key = field_or_raise(hsh, :key)
21
+ @aliases = list_field(hsh, :aliases)
20
22
  @functions = list_field(hsh, :functions)
21
23
  @alts = hash_field(hsh, :alts)
22
24
  @meta = meta_field(hsh)
@@ -58,7 +58,7 @@ module Eunomia
58
58
  def add_tags_as_meta(tags)
59
59
  tags.each do |tag|
60
60
  arr = tag.split(':')
61
- @meta[arr[0]] << arr[1] if arr.length > 1
61
+ @meta[arr[0]] << arr[1].gsub("-", " ") if arr.length > 1
62
62
  end
63
63
  end
64
64
 
@@ -13,7 +13,7 @@ module Eunomia
13
13
  class Reference
14
14
  include Common
15
15
 
16
- REFERENCE_MATCHER = /^\[([A-Za-z][A-Za-z0-9_-]+)(?::([A-Za-z0-9_-]+))?\]/
16
+ REFERENCE_MATCHER = /^\[([_]?[A-Za-z][A-Za-z0-9_-]+)(?::([A-Za-z0-9_-]+))?\]/
17
17
 
18
18
  attr_reader :key, :label
19
19
 
data/lib/eunomia/store.rb CHANGED
@@ -31,6 +31,9 @@ module Eunomia
31
31
  else
32
32
  gen = Eunomia::Generator.new(hsh_or_array)
33
33
  @generators[gen.key] = gen
34
+ gen.aliases.each do |alias_key|
35
+ @generators[alias_key] = gen
36
+ end
34
37
  end
35
38
  end
36
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eunomia
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eunomia_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - G Palmer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-15 00:00:00.000000000 Z
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Create random string with a focus on RPGs similar to fantasynamegenerators.com
14
14
  email: