text-gen 0.12.2 → 0.12.4
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/context.rb +8 -9
- data/lib/text/gen/filter/base.rb +7 -1
- data/lib/text/gen/filter/swap.rb +7 -1
- data/lib/text/gen/result.rb +12 -1
- data/lib/text/gen/runner.rb +2 -1
- data/lib/text/gen/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3682ed7222eeacaa62e5b8f19fcdf17f467808fa872ba447c4d353484dcc2bb6
|
|
4
|
+
data.tar.gz: c32eb0d27c947fdd972d6be33f20a76958ed3294b9410c4c98182266caf6ee5a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bbb90e14bfd47f7ad676917951d7b758f350d7983702c0f3dc22330cc7a7e6abc1f1c4d6c154203013f40ecf82f1d9cb77f083482bc097a789683048a49f29fe
|
|
7
|
+
data.tar.gz: e33b2ef314b0d341abc39469b4e556c9253a81842f4a79575534f2304ee8fa6159b5a0131283be662ff9b3c5ec15834656bd3a73b38e7898d8e49145273d6343
|
data/lib/text/gen/context.rb
CHANGED
|
@@ -33,19 +33,15 @@ module Text
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def with_filters(filters, offset: 0)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
filter = Filter.build(hsh, depth + offset)
|
|
39
|
-
next unless filter
|
|
36
|
+
filters_to_add = (filters || []).filter_map { |hsh| Filter.build(hsh, depth + offset) }
|
|
37
|
+
count = filters_to_add.size
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
@filters << filter
|
|
43
|
-
end
|
|
39
|
+
@filters.unshift(*filters_to_add)
|
|
44
40
|
|
|
45
41
|
begin
|
|
46
42
|
yield
|
|
47
43
|
ensure
|
|
48
|
-
@filters.
|
|
44
|
+
@filters.shift(count)
|
|
49
45
|
end
|
|
50
46
|
end
|
|
51
47
|
|
|
@@ -118,7 +114,10 @@ module Text
|
|
|
118
114
|
|
|
119
115
|
def apply_result_filters(result)
|
|
120
116
|
@filters.each do |filter|
|
|
121
|
-
|
|
117
|
+
next unless filter.respond_to?(:result)
|
|
118
|
+
next if result.filter_match?(filter.component_key)
|
|
119
|
+
|
|
120
|
+
result = filter.result(self, result)
|
|
122
121
|
return unless result
|
|
123
122
|
end
|
|
124
123
|
|
data/lib/text/gen/filter/base.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Text
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def component_key
|
|
15
|
-
"
|
|
15
|
+
"fn(#{to_s})"
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
# Shared utilities
|
|
@@ -32,6 +32,12 @@ module Text
|
|
|
32
32
|
@type ||= @filter["type"]
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
def to_s
|
|
36
|
+
return "#{ type }:#{ key }:#{ value }" if value
|
|
37
|
+
return "#{ type }:#{ key }" if key
|
|
38
|
+
type
|
|
39
|
+
end
|
|
40
|
+
|
|
35
41
|
class << self
|
|
36
42
|
def filter_name
|
|
37
43
|
@filter_name ||= name.split("::").last.downcase
|
data/lib/text/gen/filter/swap.rb
CHANGED
data/lib/text/gen/result.rb
CHANGED
|
@@ -29,6 +29,17 @@ module Text
|
|
|
29
29
|
}
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
def filter?
|
|
33
|
+
type.start_with?("fn(")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def filter_match?(component_key)
|
|
37
|
+
return true if type == component_key
|
|
38
|
+
return false unless filter?
|
|
39
|
+
|
|
40
|
+
components.any? { |c| c.filter_match?(component_key) }
|
|
41
|
+
end
|
|
42
|
+
|
|
32
43
|
def merge_all_meta(results)
|
|
33
44
|
(results || []).each { |r| @meta = Text::Gen::Meta.merge_meta(meta, r.meta) }
|
|
34
45
|
end
|
|
@@ -69,7 +80,7 @@ module Text
|
|
|
69
80
|
text: results.map(&:text).join(sep),
|
|
70
81
|
type: type,
|
|
71
82
|
value: val * mul,
|
|
72
|
-
multiplier: 1
|
|
83
|
+
multiplier: val.zero? ? mul : 1
|
|
73
84
|
).tap do |s|
|
|
74
85
|
s.components.append(*results)
|
|
75
86
|
s.merge_all_meta(results)
|
data/lib/text/gen/runner.rb
CHANGED
|
@@ -141,11 +141,12 @@ module Text
|
|
|
141
141
|
results = item["segments"].map { |seg| run_segment(context, seg) }
|
|
142
142
|
return if results.any?(&:nil?) || results.empty?
|
|
143
143
|
|
|
144
|
-
Result.merge(results,
|
|
144
|
+
result = Result.merge(results,
|
|
145
145
|
value: item["value"],
|
|
146
146
|
multiplier: item["multiplier"],
|
|
147
147
|
meta: item["meta"],
|
|
148
148
|
type: context.current_key)
|
|
149
|
+
context.apply_result_filters(result)
|
|
149
150
|
end
|
|
150
151
|
end
|
|
151
152
|
|
data/lib/text/gen/version.rb
CHANGED