subhash 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iarray.rb +26 -9
- data/lib/ihash.rb +198 -155
- data/lib/rh.rb +27 -7
- data/lib/subhash/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab2eaf62ffb511de3bde759e27863e8adf2e4d34
|
4
|
+
data.tar.gz: 8c8af07f2bd0244bd9f47a25b2a970ba36dae20f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 056c952bb3951d66fc6fe4ba9593497dea6ae3470bc181055fb4be6f0aeef0945f40d8e183a33cedd6f306e2a86b15a375bc665713dd69d027da4d13e60a4ac5
|
7
|
+
data.tar.gz: 2e87da440eb15a7cd2d539dfa9bb12643675082329dd5184d48c9917a36deaf633d5b3af0b7c87eb76530b6256ec04bebdc992aeae0c893b6e9fdf819700d6be
|
data/lib/iarray.rb
CHANGED
@@ -206,9 +206,8 @@ class Array
|
|
206
206
|
|
207
207
|
ret = _loop_array(sp)
|
208
208
|
|
209
|
-
return ret[extract]
|
210
|
-
|
211
|
-
nil
|
209
|
+
return ret[extract] if ret.is_a?(Array) && !extract.nil?
|
210
|
+
ret
|
212
211
|
end
|
213
212
|
|
214
213
|
def _loop_array(sp)
|
@@ -223,9 +222,26 @@ class Array
|
|
223
222
|
found = e.rh_get(*sp)
|
224
223
|
ret << found unless found.nil?
|
225
224
|
end
|
226
|
-
ret
|
225
|
+
_loop_array_result(ret, sp)
|
226
|
+
end
|
227
|
+
|
228
|
+
def _loop_array_result(ret, sp)
|
229
|
+
return _array_result(ret) if sp.length == 0
|
230
|
+
|
231
|
+
found = _erb_select_found(sp[0])
|
232
|
+
if found && !found[2].nil?
|
233
|
+
return ret[0] if found[2].include?('0') && ret.length == 1
|
234
|
+
return ret if found[2].include?('e')
|
235
|
+
end
|
236
|
+
_array_result(ret)
|
227
237
|
end
|
228
|
-
|
238
|
+
|
239
|
+
def _array_result(ret)
|
240
|
+
return ret if ret.length > 0
|
241
|
+
nil
|
242
|
+
end
|
243
|
+
|
244
|
+
# I ndex provided. return the value of the index.
|
229
245
|
def _get_array(sp, key)
|
230
246
|
return self[key] if sp.length == 0
|
231
247
|
|
@@ -269,14 +285,15 @@ class Array
|
|
269
285
|
end
|
270
286
|
|
271
287
|
def _keys_match(re, res, sp, opts)
|
272
|
-
empty =
|
273
|
-
empty = opts.include?('e') if opts
|
288
|
+
empty, one = _key_options(opts)
|
274
289
|
|
275
290
|
each do |e|
|
276
291
|
next unless e.is_a?(Hash)
|
277
292
|
|
278
293
|
_keys_match_hash(re, res, sp, e)
|
279
294
|
end
|
295
|
+
|
296
|
+
return res[0] if one && res.length == 1
|
280
297
|
return res if empty || res.length > 0
|
281
298
|
nil
|
282
299
|
end
|
@@ -308,11 +325,11 @@ class Array
|
|
308
325
|
next unless re.match(k_re)
|
309
326
|
|
310
327
|
if sp.length == 0
|
311
|
-
_update_res(res, k, e[k])
|
328
|
+
_update_res(res, k, e[k], false)
|
312
329
|
else
|
313
330
|
v = e[k].rh_get(sp) if e[k].structured?
|
314
331
|
|
315
|
-
_update_res(res, k, v) unless v.nil?
|
332
|
+
_update_res(res, k, v, false) unless v.nil?
|
316
333
|
end
|
317
334
|
end
|
318
335
|
res
|
data/lib/ihash.rb
CHANGED
@@ -155,30 +155,149 @@ class Hash
|
|
155
155
|
# - +p+ : Array of String/Symbol or Regexp. It contains the list of keys
|
156
156
|
# tree to follow and check existence in self.
|
157
157
|
#
|
158
|
-
# In the subhash structure, each
|
158
|
+
# In the subhash structure, each hierachy tree level is a Hash or an
|
159
159
|
# Array.
|
160
160
|
#
|
161
161
|
# At a given level the top key will be interpreted as follow and used as
|
162
162
|
# data selection if the object is:
|
163
163
|
# - Hash:
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
164
|
+
# - RegExp match: (Version 0.1.2)
|
165
|
+
# You can define key matching with Regexp or with a structured string:
|
166
|
+
# - Regexp or '/<Regexp>/<opts>' or '[<Regexp>]' :
|
167
|
+
# For each key in self tree, matching <Regexp>, the value associated
|
168
|
+
# to the key will be added as a new item in an ARRAY.
|
169
|
+
#
|
170
|
+
# - '{/<Regexp>/<opts>}' :
|
171
|
+
# For each key in self tree, matching <Regexp>, the value and the
|
172
|
+
# key will be added as a new item (key => value) in a Hash
|
173
|
+
#
|
174
|
+
# '<Regexp' is a string representing the Regexp to use.
|
175
|
+
# Please note that :
|
176
|
+
# data.rh_get(/test/) is equivalent to data.rh_get('/test/'). This
|
177
|
+
# second syntax provide additional feature, with <opts>
|
178
|
+
#
|
179
|
+
# '<opts>' is an optional string representing a list of characters
|
180
|
+
# to set options for matching results.
|
181
|
+
# Options supported are:
|
182
|
+
# - 'e' : If nothing match, the selection will return an empty Array
|
183
|
+
# By default, it return nil, Usually, it is eliminated in the
|
184
|
+
# final result. (Version 0.1.3)
|
185
|
+
# - '0' : If only one match, the selection will return the value
|
186
|
+
# of that alone matching RegExp. (Version 0.1.5)
|
187
|
+
#
|
188
|
+
# - ERB can be used to select a subhash or extract a key.
|
189
|
+
# (Version 0.1.3)
|
190
|
+
# - ERB Selection
|
191
|
+
# The ERB selection is detected by a string containing
|
192
|
+
# '<%= ... %>opts|something'
|
193
|
+
# The ERB code must return a boolean or 'true' to consider the
|
194
|
+
# current data context as queriable with a key.
|
195
|
+
# - 'something' can be any key (string, symbol or even an ERB
|
196
|
+
# extraction)
|
197
|
+
# '<opts>' is an optional string representing a list of characters
|
198
|
+
# to set options for matching results. (Version 0.1.5)
|
199
|
+
# Options supported are:
|
200
|
+
# - 'e' : If nothing match, the selection will return an empty Array
|
201
|
+
# By default, it return nil, Usually, it is eliminated in the
|
202
|
+
# final result.
|
203
|
+
# - '0' : If only one match, the selection will return the value
|
204
|
+
# of that alone matching RegExp.
|
205
|
+
# - ERB Extraction
|
206
|
+
# The ERB selection is detected by a string containing simply
|
207
|
+
# '<%= ... %>'
|
208
|
+
# The result of that ERB call should return a string which will
|
209
|
+
# become a key to extract data from the current data context.
|
210
|
+
#
|
211
|
+
# NOTE! ERB convert any symbol using to_s. If you need to get a key
|
212
|
+
# as a symbol, you will to add : in front of the context string:
|
213
|
+
#
|
214
|
+
# Ex:
|
215
|
+
# RhContext.context = :test
|
216
|
+
# data.rh_get('<%= context =>') # is equivalent to
|
217
|
+
# # data.rh_get('test')
|
218
|
+
#
|
219
|
+
# RhContext.context = ':test'
|
220
|
+
# data.rh_get('<%= context =>') # is equivalent to
|
221
|
+
# # data.rh_get(:test)
|
222
|
+
#
|
223
|
+
# The ERB context by default contains:
|
224
|
+
# - at least a 'data' attribute. It contains the current Hash/Array
|
225
|
+
# level data in the data structure hierarchy.
|
226
|
+
# - optionally a 'context' attribute. Contains any kind of data.
|
227
|
+
# This is typically set before any call to rh_* functions.
|
228
|
+
#
|
229
|
+
# you can introduce more data in the context, by creating a derived
|
230
|
+
# class from RhContext.ERBConfig. This will ensure attribute
|
231
|
+
# data/context exist in the context.
|
232
|
+
# Ex:
|
233
|
+
#
|
234
|
+
# class MyContext < RhContext::ERBConfig
|
235
|
+
# attr_accessor :config # Added config in context
|
236
|
+
# end
|
237
|
+
#
|
238
|
+
# RhContext.erb = MyContext.new
|
239
|
+
# RhContext.erb.config = my_config
|
240
|
+
# data.rh_get(...)
|
241
|
+
#
|
242
|
+
# data = YAML.parse("---
|
243
|
+
# :test:
|
244
|
+
# :test2: value1
|
245
|
+
# :test3: value2
|
246
|
+
# :test4: value3
|
247
|
+
# :arr1: [ 4, value4]
|
248
|
+
# :arr2:
|
249
|
+
# - :test5: value5
|
250
|
+
# :test6: value6
|
251
|
+
# - :test7: value7
|
252
|
+
# :test8
|
253
|
+
# :test5: value8
|
254
|
+
# - :test5: value9")
|
255
|
+
#
|
256
|
+
# # Default context:
|
257
|
+
# RhContext.erb = nil
|
258
|
+
# # Filtering using |
|
259
|
+
# data.rh_get(:arr2, '<%= data.key?(:test8) %>|:test5')
|
260
|
+
# # => ['value8']
|
261
|
+
# RhContext.context = :test6
|
262
|
+
# data.rh_get(:arr2, '<%= context %>')
|
263
|
+
# # => ['value6']
|
172
264
|
#
|
173
265
|
# - Array:
|
174
|
-
# If the top key type is:
|
266
|
+
# *Data selection :* If the top key type is:
|
175
267
|
# - Fixnum : The key is considered as the Array index.
|
176
|
-
# it will get in self[p[0]]
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
268
|
+
# it will get in self[p[0]] (Version 0.1.3)
|
269
|
+
#
|
270
|
+
# # Data selection:
|
271
|
+
# data.rh_get(:arr2, 1, :test5) # => 'value8'
|
272
|
+
#
|
273
|
+
# - Range : Range extract only some element from the Array.
|
274
|
+
# (Version 0.1.3)
|
275
|
+
#
|
276
|
+
# # Data selection:
|
277
|
+
# data.rh_get(:arr2, 0..1, :test5) # => ['value5', 'value8']
|
278
|
+
# data.rh_get(:arr2, 1..2, :test5) # => ['value8', 'value9']
|
279
|
+
#
|
280
|
+
# *Data extraction :* If the top key type is:
|
281
|
+
# - '=[<Fixnum|Range>]' where
|
282
|
+
# - Fixnum : From found result, return the content of result[<Fixnum>]
|
283
|
+
# => subhash data found. It can return nil (Version 0.1.3)
|
284
|
+
# - Range : From found result, return the Range context of
|
285
|
+
# result[<Range>]
|
286
|
+
# => Array of (subhash data found) (Version 0.1.3)
|
287
|
+
#
|
288
|
+
# # data extraction. By default:
|
289
|
+
# # data.rh_get(:arr2, :test5) return ['value5','value8','value9']
|
290
|
+
# # then
|
291
|
+
# data.rh_get(:arr2, '=[0]', :test5) # => 'value5'
|
292
|
+
# data.rh_get(:arr2, '=[0..1]', :test5)
|
293
|
+
# # => ['value5', 'value8']
|
294
|
+
# data.rh_get(:arr2, '=[0..3]', :test5)
|
295
|
+
# # => ['value5', 'value8','value9']
|
296
|
+
#
|
297
|
+
# - String/Symbol : loop in array to find in elements an Hash to apply.
|
298
|
+
# So, for each Hash elements, it follows the Hash rule.
|
299
|
+
# The result will be stored in an Array of matching elements.
|
300
|
+
# (Version 0.1.3)
|
182
301
|
#
|
183
302
|
# * *Returns* :
|
184
303
|
# - +value+ : Represents the data found in the tree. Can be of any type.
|
@@ -188,147 +307,69 @@ class Hash
|
|
188
307
|
#
|
189
308
|
# Example:(implemented in spec)
|
190
309
|
#
|
191
|
-
# data =
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
310
|
+
# data = {
|
311
|
+
# :test => {
|
312
|
+
# :test2 = 'value1'
|
313
|
+
# :test3 => 'value2' },
|
314
|
+
# :test4 => 'value3'
|
315
|
+
# :arr1 => [ 4, 'value4']
|
316
|
+
# :arr2 => [{ :test5 = 'value5', :test6 = 'value6'},
|
317
|
+
# { :test7 = 'value7'},
|
318
|
+
# :test8,
|
319
|
+
# { :test5 = 'value8' }
|
320
|
+
# ]
|
321
|
+
# }
|
203
322
|
#
|
204
323
|
# so:
|
205
|
-
#
|
206
|
-
#
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
324
|
+
# data.rh_get(:test) => {:test2 => 'value1', :test3 => 'value2'}
|
325
|
+
# data.rh_get(:test5) => nil
|
326
|
+
# data.rh_get(:test, :test2) => 'value1'
|
327
|
+
# data.rh_get(:test, :test2, :test5) => nil
|
328
|
+
# data.rh_get(:test, :test5 ) => nil
|
329
|
+
# data.rh_get => { :test => {:test2 => 'value1', :test3 => 'value2'},
|
211
330
|
# :test4 => 'value3'}
|
212
331
|
#
|
213
332
|
# New features: 0.1.2
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
-
#
|
240
|
-
#
|
241
|
-
#
|
333
|
+
# data.rh_get(:test, /^test/) # => []
|
334
|
+
# data.rh_get(:test, /^:test/) # => ['value1', 'value2']
|
335
|
+
# data.rh_get(:test, /^:test.*/) # => ['value1', 'value2']
|
336
|
+
# data.rh_get(:test, '/:test.*/') # => ['value1', 'value2']
|
337
|
+
# data.rh_get(:test, '/:test.*/') # => ['value1', 'value2']
|
338
|
+
# data.rh_get(:test, '[/:test.*/]') # => ['value1', 'value2']
|
339
|
+
# data.rh_get(:test, '{/:test2/}') # => {:test2 => 'value1'}
|
340
|
+
# data.rh_get(:test, '{/test/}')
|
341
|
+
# # => {:test2 => 'value1', :test3 => 'value2'}
|
342
|
+
# data.rh_get(:test, '{:test2}') # => {:test2 => 'value1'}
|
343
|
+
# data.rh_get(:test, '{:test2}') # => {:test2 => 'value1'}
|
344
|
+
#
|
345
|
+
# data.rh_get(:arr2, :test6) # => ['value6']
|
346
|
+
# data.rh_get(:arr2, :test8) # => nil
|
347
|
+
# data.rh_get(:arr2, :test5) # => ['value5', 'value8']
|
348
|
+
# data.rh_get(/arr/, :test5) # => [['value5', 'value8']]
|
349
|
+
# data.rh_get('{/arr/}', :test5) # => { :arr2 => ['value5', 'value8']}
|
350
|
+
# data.rh_get('{/arr/}', '{:test5}')
|
351
|
+
# # => { :arr2 => {:test5 => ['value5', 'value8']}}
|
352
|
+
#
|
353
|
+
# data.rh_get(:arr2, 2) # => nil
|
354
|
+
# data.rh_get(:arr2, 0) # => { :test5 = 'value5',
|
355
|
+
# # :test6 = 'value6'}
|
356
|
+
# data.rh_get(:arr2, 1) # => { :test7 = 'value7',
|
357
|
+
# # :test8
|
358
|
+
# # :test5 = 'value8' }
|
359
|
+
# data.rh_get(:arr2, 1, :test7) # => 'value7'
|
360
|
+
# data.rh_get(:arr2, 0, :test7) # => nil
|
242
361
|
#
|
243
362
|
# New features: 0.1.3
|
244
363
|
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
#
|
251
|
-
#
|
252
|
-
#
|
253
|
-
#
|
254
|
-
# - ERB Extraction
|
255
|
-
# The ERB selection is detected by a string containing simply
|
256
|
-
# '<%= ... %>'
|
257
|
-
# The result of that ERB call should return a string which will become a
|
258
|
-
# key to extract data from the current data context.
|
259
|
-
#
|
260
|
-
# NOTE! ERB convert any symbol using to_s. If you need to get a key as a
|
261
|
-
# symbol, you will to add : in front of the context string:
|
262
|
-
#
|
263
|
-
# Ex:
|
264
|
-
# RhContext.context = :test
|
265
|
-
# data.rh_get('<%= context =>') # is equivalent to data.rh_get('test')
|
266
|
-
#
|
267
|
-
# RhContext.context = ':test'
|
268
|
-
# data.rh_get('<%= context =>') # is equivalent to data.rh_get(:test)
|
269
|
-
#
|
270
|
-
# The ERB context by default contains:
|
271
|
-
# - at least a 'data' attribute. It contains the current Hash/Array
|
272
|
-
# level data in the data structure hierarchy.
|
273
|
-
# - optionally a 'context' attribute. Contains any kind of data.
|
274
|
-
# This is typically set before any call to rh_* functions.
|
275
|
-
#
|
276
|
-
# you can introduce more data in the context, by creating a derived class
|
277
|
-
# from RhContext.ERBConfig. This will ensure attribute data/context exist
|
278
|
-
# in the context.
|
279
|
-
# Ex:
|
280
|
-
#
|
281
|
-
# class MyContext < RhContext::ERBConfig
|
282
|
-
# attr_accessor :config # Added config in context
|
283
|
-
# end
|
284
|
-
#
|
285
|
-
# RhContext.erb = MyContext.new
|
286
|
-
# RhContext.erb.config = my_config
|
287
|
-
# data.rh_get(...)
|
288
|
-
#
|
289
|
-
# data = YAML.parse("---
|
290
|
-
# :test:
|
291
|
-
# :test2: value1
|
292
|
-
# :test3: value2
|
293
|
-
# :test4: value3
|
294
|
-
# :arr1: [ 4, value4]
|
295
|
-
# :arr2:
|
296
|
-
# - :test5: value5
|
297
|
-
# :test6: value6
|
298
|
-
# - :test7: value7
|
299
|
-
# :test8
|
300
|
-
# :test5: value8
|
301
|
-
# - :test5: value9")
|
302
|
-
#
|
303
|
-
# # Default context:
|
304
|
-
# RhContext.erb = nil
|
305
|
-
# # Filtering using |
|
306
|
-
# data.rh_get(:arr2, '<%= data.key?(:test8) %>|:test5')
|
307
|
-
# # => ['value8']
|
308
|
-
# RhContext.context = :test6
|
309
|
-
# data.rh_get(:arr2, '<%= context %>')
|
310
|
-
# # => ['value6']
|
311
|
-
#
|
312
|
-
# Introduce Array extraction (Fixnum and Range)
|
313
|
-
# When a data at a current level is an Array, get/exist?/lexist? interpret
|
314
|
-
# - the string '=[<Fixnum|Range>]' where
|
315
|
-
# - Fixnum : From found result, return the content of result[<Fixnum>]
|
316
|
-
# => subhash data found. It can return nil
|
317
|
-
# - Range : From found result, return the Range context of result[<Range>]
|
318
|
-
# => Array of (subhash data found)
|
319
|
-
# - the Range. complete the Array index selection.
|
320
|
-
# ex: [:test1, {:test2 => :value1}].rh_get(0..1, :test2)
|
321
|
-
#
|
322
|
-
# # data extraction. By default:
|
323
|
-
# # data.rh_get(:arr2, :test5) return ['value5', 'value8', 'value9']
|
324
|
-
# # then
|
325
|
-
# data.rh_get(:arr2, '=[0]', :test5) # => 'value5'
|
326
|
-
# data.rh_get(:arr2, '=[0..1]', :test5) # => ['value5', 'value8']
|
327
|
-
# data.rh_get(:arr2, '=[0..3]', :test5) # => ['value5', 'value8','value9']
|
328
|
-
#
|
329
|
-
# # Data selection:
|
330
|
-
# data.rh_get(:arr2, 0..1, :test5) # => ['value5', 'value8']
|
331
|
-
# data.rh_get(:arr2, 1..2, :test5) # => ['value8', 'value9']
|
364
|
+
# - Introduce ERB context rh_get/exist?/lexist? functions:
|
365
|
+
# - Introduce Array extraction (Fixnum and Range)
|
366
|
+
#
|
367
|
+
# New features: 0.1.5
|
368
|
+
#
|
369
|
+
# A new option '0' has been added to the RegExp match
|
370
|
+
# It permits to return the value of element 0 of the array built by the
|
371
|
+
# matching result.
|
372
|
+
#
|
332
373
|
def rh_get(*p)
|
333
374
|
p = p.flatten
|
334
375
|
return self if p.length == 0
|
@@ -632,26 +673,28 @@ class Hash
|
|
632
673
|
end
|
633
674
|
|
634
675
|
def _keys_match(re, res, sp, opts)
|
635
|
-
empty =
|
636
|
-
empty = opts.include?('e') if opts
|
676
|
+
empty, one = _key_options(opts)
|
637
677
|
|
638
|
-
_keys_match_loop(re, res, sp)
|
678
|
+
_keys_match_loop(re, res, sp, opts)
|
639
679
|
|
680
|
+
return res[0] if one && res.is_a?(Array) && res.length == 1
|
640
681
|
return res if empty || res.length > 0
|
641
682
|
nil
|
642
683
|
end
|
643
684
|
|
644
|
-
def _keys_match_loop(re, res, sp)
|
685
|
+
def _keys_match_loop(re, res, sp, opts)
|
686
|
+
_, one = _key_options(opts)
|
687
|
+
|
645
688
|
keys.sort.each do |k|
|
646
689
|
k_re = _key_to_s(k)
|
647
690
|
next unless re.match(k_re)
|
648
691
|
|
649
692
|
if sp.length == 0
|
650
|
-
_update_res(res, k, self[k])
|
693
|
+
_update_res(res, k, self[k], one)
|
651
694
|
else
|
652
695
|
v = self[k].rh_get(sp) if [Array, Hash].include?(self[k].class)
|
653
696
|
|
654
|
-
_update_res(res, k, v) unless v.nil?
|
697
|
+
_update_res(res, k, v, one) unless v.nil?
|
655
698
|
end
|
656
699
|
end
|
657
700
|
end
|
data/lib/rh.rb
CHANGED
@@ -77,15 +77,22 @@ module Rh
|
|
77
77
|
# Return the erb call return
|
78
78
|
# true otherwise ie Selected by default.
|
79
79
|
def _erb_select(key)
|
80
|
-
|
80
|
+
found = _erb_select_found(key)
|
81
|
+
return true, key unless found
|
82
|
+
|
81
83
|
RhContext.data = self
|
82
84
|
|
83
|
-
found = /^(<%=.*%>)\|/.match(key)
|
84
85
|
key = key.clone
|
85
86
|
key[found[0]] = ''
|
86
87
|
[RhContext.get(found[1]) == 'true', _convert_key(key)]
|
87
88
|
end
|
88
89
|
|
90
|
+
def _erb_select_found(key)
|
91
|
+
return false unless key.is_a?(String) && key =~ /^<%=.*%>([0-9a-z]*)?\|/
|
92
|
+
|
93
|
+
/^(<%=.*%>)([0-9a-z]*)?\|/.match(key)
|
94
|
+
end
|
95
|
+
|
89
96
|
def _erb_extract(key)
|
90
97
|
return key unless key.is_a?(String) && key =~ /^<%=.*%>[^|]?/
|
91
98
|
RhContext.data = self
|
@@ -202,13 +209,21 @@ module RhGet
|
|
202
209
|
return [nil, nil, nil] unless key.is_a?(String)
|
203
210
|
|
204
211
|
regs = []
|
205
|
-
regs << [%r{^/(.*)/(
|
206
|
-
regs << [%r{^\[/(.*)/(
|
207
|
-
regs << [%r{^\{/(.*)/(
|
212
|
+
regs << [%r{^/(.*)/([e0])*$}, []]
|
213
|
+
regs << [%r{^\[/(.*)/([e0])*\]$}, []]
|
214
|
+
regs << [%r{^\{/(.*)/([e0])*\}$}, {}]
|
208
215
|
|
209
216
|
_loop_on_regs(regs, key)
|
210
217
|
end
|
211
218
|
|
219
|
+
def _key_options(opts)
|
220
|
+
empty = false
|
221
|
+
empty = opts.include?('e') if opts
|
222
|
+
one = false
|
223
|
+
one = opts.include?('0') if opts
|
224
|
+
[empty, one]
|
225
|
+
end
|
226
|
+
|
212
227
|
def _loop_on_regs(regs, key)
|
213
228
|
regs.each do |r|
|
214
229
|
init = r[1]
|
@@ -223,9 +238,14 @@ module RhGet
|
|
223
238
|
k
|
224
239
|
end
|
225
240
|
|
226
|
-
def _update_res(res, k, v)
|
241
|
+
def _update_res(res, k, v, one)
|
227
242
|
res << v if res.is_a?(Array)
|
228
|
-
|
243
|
+
return unless res.is_a?(Hash)
|
244
|
+
if one && v.is_a?(Array) && v.length == 1
|
245
|
+
res[k] = v[0]
|
246
|
+
else
|
247
|
+
res[k] = v
|
248
|
+
end
|
229
249
|
end
|
230
250
|
end
|
231
251
|
|
data/lib/subhash/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subhash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christophe Larsonneur
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|