curly_bracket_parser 0.9.2 → 0.9.9

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: 378a04d38936fc44f74b1f4f970d098865a2a48c32cc61632c2fcf399fcec705
4
- data.tar.gz: 68afedba437f8b335793bb45f1bb64c6c7b5a6846e33224b52eed05db042fe49
3
+ metadata.gz: c287b3fc82c91116b7c0ca2f982b81bac5c37e4ca286cd1ea8606de75e0c214f
4
+ data.tar.gz: 04f59765b1f59ea540d1e152bbc88c0294ca5adc681f30bf1efed3a117cb3afa
5
5
  SHA512:
6
- metadata.gz: 955864e2612341beb012f20e79aa439ec44c90e59e39bb0b54bcd813b0d680f22d8c24f23337697e1d4caabbed4dfdc5f2791ac8358afabd985d66914941b47c
7
- data.tar.gz: 750d7cbd409660d96ad623c9b86d8fed53f9efae81cb268a2bf0b77454ad80abfd515f16bb6d15e1b9d4f7aca6c055bf6dee6e0a75fbdd6368d59292f3f0198d
6
+ metadata.gz: 685345c3a8551e0749742550f2dae6784501fefa07318b8e76b2b30fd743c96d1571d2550bee0731a1c1609d82055ec39ff943a6aebf3c39db435d4686d8e01c
7
+ data.tar.gz: a19c4ffb4fe23ce4945023604aeb34ee28a88bd6f89cf2df08f5eab63151fbb0f1ec6b7ec337f6cc8c0b8d2b57c8dacbfec19cbec7b70b22d68cc8b4caf965c6
@@ -40,7 +40,9 @@ module CurlyBracketParser
40
40
  if CurlyBracketParser.any_variable_included? string
41
41
  loop do
42
42
  variables(string).each do |string_var|
43
- name, filter = decode_variable(string_var)
43
+ dec = decode_variable(string_var)
44
+ name = dec[:name]
45
+ filter = dec[:filter]
44
46
  if variables[name.to_sym]
45
47
  value = if filter
46
48
  process_filter(filter, variables[name.to_sym])
@@ -212,11 +214,16 @@ module CurlyBracketParser
212
214
  # Unregister / remove an existing default variable
213
215
  #
214
216
  # @param [String] name of the variable
217
+ # @return [Boolean] true if variable existed and was unregistered, false if it didn't exist
215
218
  def self.unregister_default_var(name)
216
219
  @@registered_default_vars ||= {}
217
220
  name = name.to_s
218
- @@registered_default_vars.delete(name)
219
- nil
221
+ if @@registered_default_vars[name]
222
+ @@registered_default_vars.delete(name)
223
+ true
224
+ else
225
+ false
226
+ end
220
227
  end
221
228
 
222
229
  #----------------------------------------------------------------------------------------------------
@@ -247,26 +254,30 @@ module CurlyBracketParser
247
254
  # '{{var_name|filter_name}}' => { name: 'var_name', filter: 'filter_name' }
248
255
  #
249
256
  # @param [String] variable
250
- # @return [Array(String, String)] name, filter
257
+ # @return [Hash<String => String>] name, filter
251
258
  def self.decode_variable(variable)
252
- var = decoded_variables(variable).first
253
- [var.keys.first, var.values.first]
259
+ decoded_variables(variable).first
254
260
  end
255
261
 
256
262
  #----------------------------------------------------------------------------------------------------
257
263
 
258
- # scans the given url for variables with pattern '{{var}}'
264
+ # Scans the given url for variables with pattern '{{var|optional_filter}}'
265
+ #
266
+ # @example
267
+ # 'The variable {{my_var|my_filter}} is inside this string' => [{ name: "my_var", filter: "my_filter"}]
268
+ #
259
269
  # @param [String] string to scan
260
270
  # @return [Array<Hash<Symbol => String>>] array of variable names and its filters
261
271
  def self.decoded_variables(string)
262
- var_name = 0
263
- var_filter = 1
264
- string.scan(VARIABLE_DECODER_REGEX).map { |e| { "#{e[var_name].strip}": e[var_filter].strip != '' ? e[var_filter].strip : nil } }.flatten
272
+ var_name_index = 0
273
+ var_filter_index = 1
274
+ string.scan(VARIABLE_DECODER_REGEX).map { |e| { name: "#{e[var_name_index].strip}", filter: e[var_filter_index].strip != '' ? e[var_filter_index].strip : nil } }.flatten
265
275
  end
266
276
 
267
277
  #----------------------------------------------------------------------------------------------------
268
278
 
269
- # scans the given url for variables with pattern '{{var}}'
279
+ # Scans the given url for variables with pattern '{{var|optional_filter}}'
280
+ #
270
281
  # @param [String] string to scan
271
282
  # @return [Array<String>] array of variable names and its filters
272
283
  def self.variables(string)
@@ -276,7 +287,8 @@ module CurlyBracketParser
276
287
  #----------------------------------------------------------------------------------------------------
277
288
 
278
289
  # Check if any variable is included in the given string
279
- # @param [Object] string
290
+ #
291
+ # @param [String] string name of variable to check for
280
292
  # @return [Boolean] true if any variable is included in the given string, otherwise false
281
293
  def self.any_variable_included?(string)
282
294
  string.match(VARIABLE_REGEX) != nil
@@ -285,8 +297,9 @@ module CurlyBracketParser
285
297
  #----------------------------------------------------------------------------------------------------
286
298
 
287
299
  # Check if one of the given variable names is included in the given string
300
+ #
288
301
  # @param [Array<String>] variable_names
289
- # @param [String] string
302
+ # @param [String] string name of variable to check for
290
303
  # @return [Boolean] true if one given variable name is included in given the string, otherwise false
291
304
  def self.includes_one_variable_of(variable_names, string)
292
305
  decoded_variables(string).each do |dvar|
@@ -1,3 +1,3 @@
1
1
  module CurlyBracketParser
2
- VERSION = '0.9.2'.freeze
2
+ VERSION = '0.9.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curly_bracket_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthäus Beyrle