text-gen 0.13.4 → 0.14.1
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/lib/text/gen/filter/store.rb +52 -0
- data/lib/text/gen/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0255cbef217f9ce287acc23649201b52208d57fbdda0bc7da578976cc0a49fcd
|
|
4
|
+
data.tar.gz: 0fe740846a3fbebd37ec8e6386b1e025dff157e8a50abd117c6b0d989b46ace2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cbeb43e896e3e9d5646f8cf18c910da6580b7a034e2a504877cebf177729205a66ee41fcb4be2bfe8315dcf2f566d83d5dd00d857d5d7543fc7f840b55981daf
|
|
7
|
+
data.tar.gz: a553b2e3c50470797b078b0cc0da665f485f7ae7570be7f7f3325bd807c6ea782342f894528820f79321cf596cd87ab62f3189aa0f426e0230e8a2d88ce9d721
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Text
|
|
4
|
+
module Gen
|
|
5
|
+
module Filter
|
|
6
|
+
# Store appends a meta value based on the current historic stack of the
|
|
7
|
+
# result. The key names a component in the result's component tree (a
|
|
8
|
+
# builder key such as `nation-name`, with or without a category prefix)
|
|
9
|
+
# and the value is the meta key that the component's text is appended to.
|
|
10
|
+
#
|
|
11
|
+
# For example `store:nation-name:short-name` on a `nation` builder that
|
|
12
|
+
# generates "The Kingdom of Boring" appends "Boring" to
|
|
13
|
+
# `result.meta["short-name"]` so it can be referenced later with
|
|
14
|
+
# `match`/`select` or read from the final result.
|
|
15
|
+
class Store < Base
|
|
16
|
+
def result(context, result)
|
|
17
|
+
return result if @depth && context.depth != @depth
|
|
18
|
+
return result if key.nil? || value.nil?
|
|
19
|
+
|
|
20
|
+
component = find_component(result)
|
|
21
|
+
return result if component.nil?
|
|
22
|
+
|
|
23
|
+
new_meta = Text::Gen::Meta.append_kv(result.meta.dup, value, component.text)
|
|
24
|
+
return result if new_meta == result.meta
|
|
25
|
+
|
|
26
|
+
Result.from(result, type: component_key, meta: new_meta)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# Depth-first search of the result and its components for the first
|
|
32
|
+
# component whose type matches the key
|
|
33
|
+
def find_component(result)
|
|
34
|
+
return result if type_matches?(result.type)
|
|
35
|
+
|
|
36
|
+
result.components.each do |component|
|
|
37
|
+
found = find_component(component)
|
|
38
|
+
return found if found
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def type_matches?(type)
|
|
45
|
+
return false if type.nil?
|
|
46
|
+
|
|
47
|
+
type == key || type.split(">").last == key
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/text/gen/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: text-gen
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- G Palmer
|
|
@@ -58,6 +58,7 @@ files:
|
|
|
58
58
|
- lib/text/gen/filter/remember.rb
|
|
59
59
|
- lib/text/gen/filter/replace.rb
|
|
60
60
|
- lib/text/gen/filter/select.rb
|
|
61
|
+
- lib/text/gen/filter/store.rb
|
|
61
62
|
- lib/text/gen/filter/swap.rb
|
|
62
63
|
- lib/text/gen/filter/titleize.rb
|
|
63
64
|
- lib/text/gen/filter/upcase.rb
|