re_duxml 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/re_duxml.rb +19 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d5fa8b77a1b0b291c282574fc9a17cbd1e0de6
|
4
|
+
data.tar.gz: 9e29841defd5a865ce9644da31f58b6dfc1f955a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55ef6a539b7887e2b23055cb7e1ad8f751fc7661d2f91d92e095238ddb8c834580097311a837e77594d7f4e998033048e1ff91bd212526a00c89b449a06297ee
|
7
|
+
data.tar.gz: 4f89848c40a34c56fd6ee9545ff5bbb2d5bd2c0b6d290f42d94669e5016772cccd94d5136ccec3ab869b07909be4e6d0365a581332a44a159cb0452e751ba010
|
data/lib/re_duxml.rb
CHANGED
@@ -85,20 +85,27 @@ module ReDuxml
|
|
85
85
|
# @param param_hash [Hash] keys are parameter names, values are parameter values e.g. {var0: 'param', var1: 'eter'}
|
86
86
|
# @return [String] content_str with parameter values substituted and algebraically reduced if any unknown parameters remain e.g. 'a parameter string @(var2)'
|
87
87
|
def resolve_str(content_str, param_hash)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
output_str = content_str.clone
|
89
|
+
questions = find_exprs content_str
|
90
|
+
return output_str if questions.empty?
|
91
|
+
questions.each do |question|
|
92
|
+
reply = Macro.new e.evaluate(question, param_hash).to_s
|
93
|
+
replacement_str = reply.parameterized? ? reply.macro_string : reply.demacro
|
94
|
+
macro_string = Macro.new(question).macro_string
|
95
|
+
output_str.gsub!(macro_string, replacement_str)
|
96
|
+
end
|
97
|
+
output_str
|
94
98
|
end
|
95
99
|
|
96
100
|
# @param str [String] string that may contain parameter expression e.g. 'asdf @(param + 2) asdf'
|
97
|
-
# @return [String] macro
|
98
|
-
def
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
# @return [Array[String]] array of macro strings e.g. 'asdf @(param + 2) asdf' => 'param + 2'
|
102
|
+
def find_exprs(str)
|
103
|
+
expressions = []
|
104
|
+
str.scan('@(') do |c|
|
105
|
+
expr_start_index = $~.offset(0)[0] # gets index of current match
|
106
|
+
expr_end_index = find_close_parens_index str[expr_start_index+1..-1]
|
107
|
+
expressions << str[expr_start_index+2, expr_end_index-1]
|
108
|
+
end
|
109
|
+
expressions
|
103
110
|
end
|
104
111
|
end # module Dux
|