curly_bracket_parser 1.0.0 → 1.0.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/README.md +4 -1
- data/lib/curly_bracket_parser/version.rb +1 -1
- data/lib/curly_bracket_parser.rb +7 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc6e9152c4a5928dd20a24cc8cb59ace5b9c5b5b66204b118061b28cff3f33b
|
4
|
+
data.tar.gz: 851fa1b633944e37968d31755b786939bea79afa624b4e2135167bb3e832555c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 162491b1ca8833964b29e38482806b479f6f1ab5d9f0505368ce83b219e9fe3953d2a03aac4d592ade1ad5182365ca344c471f5847cb9abd36a849dd0c8925f5
|
7
|
+
data.tar.gz: 697839790e56524019c7e35a2ebb58f441f27f74458cfbf2d6f4bf1e91d038e777368b9a637f20c2d48d7fe022baa3d8188ac439d400bf524989cb28731812a3
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# curly_bracket_parser
|
2
|
+

|
3
|
+

|
4
|
+
[](LICENSE)
|
2
5
|
|
3
|
-
Ruby gem providing a simple parser to replace curly brackets `{{like_this}}` inside strings like URLs, texts or even files easily.
|
6
|
+
> Ruby gem providing a simple parser to replace curly brackets `{{like_this}}` inside strings like URLs, texts or even files easily.
|
4
7
|
|
5
8
|
Additional support for build-in filters and custom filters make them more powerful. `{{example|my_filter}}`
|
6
9
|
|
data/lib/curly_bracket_parser.rb
CHANGED
@@ -37,9 +37,11 @@ module CurlyBracketParser
|
|
37
37
|
def self.parse(string, variables, unresolved_vars: :raise, replace_pattern: "##\\1##")
|
38
38
|
variables ||= {}
|
39
39
|
result_string = string.clone
|
40
|
+
# symbolize keys
|
41
|
+
variables = variables.map { |key, value| [key.to_sym, value] }.to_h
|
40
42
|
if CurlyBracketParser.any_variable_included? string
|
41
43
|
loop do
|
42
|
-
variables(
|
44
|
+
variables(result_string).each do |string_var|
|
43
45
|
dec = decode_variable(string_var)
|
44
46
|
name = dec[:name]
|
45
47
|
filter = dec[:filter]
|
@@ -56,7 +58,9 @@ module CurlyBracketParser
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
# break if no more given variable is available
|
59
|
-
|
61
|
+
unless any_variable_included?(result_string) && includes_one_variable_of(variables.keys, result_string)
|
62
|
+
break
|
63
|
+
end
|
60
64
|
end
|
61
65
|
case unresolved_vars
|
62
66
|
when :raise
|
@@ -303,7 +307,7 @@ module CurlyBracketParser
|
|
303
307
|
# @return [Boolean] true if one given variable name is included in given the string, otherwise false
|
304
308
|
def self.includes_one_variable_of(variable_names, string)
|
305
309
|
decoded_variables(string).each do |dvar|
|
306
|
-
return true if variable_names.include?(dvar[:name])
|
310
|
+
return true if variable_names.map(&:to_sym).include?(dvar[:name].to_sym)
|
307
311
|
end
|
308
312
|
false
|
309
313
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curly_bracket_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthäus Beyrle
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lucky_case
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
113
|
+
rubygems_version: 3.1.4
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Simple parser to replace variables inside templates/strings and files
|