structurebutcher 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/structurebutcher.rb +10 -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: 2f8a698fe9243394623cc78e9d4615c763754ba6
|
4
|
+
data.tar.gz: e82e5c52fff3d88627cfecab4d86119c67687c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bae99c1382dd400295eb3837abd3cc1323be2d8f907fca289d0b35eca0dba24b2857d587246ecde1a5dd856a6b0ee274af5ec04adc04507d06d8b5c2c677628
|
7
|
+
data.tar.gz: ca00617bce45de9ee8bf81ab2ab8244e0dfdc74d224ae07fc4893369aacbd1bb68f4d77bcd4aafff42848a511bd30c614495ff4b26c672c21ab122296210022a
|
data/lib/structurebutcher.rb
CHANGED
@@ -11,8 +11,16 @@ require 'base64'
|
|
11
11
|
#amputate, implantate
|
12
12
|
|
13
13
|
class StructureButcher
|
14
|
+
def split_escape(str)
|
15
|
+
output = []
|
16
|
+
str.scan(/(?>\\.|[^\\.])+/) do |chunk|
|
17
|
+
output.push( chunk.gsub(/\\(.)/, '\1') )
|
18
|
+
end
|
19
|
+
return output
|
20
|
+
end
|
21
|
+
|
14
22
|
def amputate(body, slot)
|
15
|
-
keys = slot
|
23
|
+
keys = split_escape(slot)
|
16
24
|
result = body
|
17
25
|
while (key = keys.shift)
|
18
26
|
result = result[key]
|
@@ -25,7 +33,7 @@ class StructureButcher
|
|
25
33
|
last_key = keys.pop
|
26
34
|
area = body
|
27
35
|
while (key = keys.shift)
|
28
|
-
if area.has_key?(key)
|
36
|
+
if not area.has_key?(key)
|
29
37
|
then area[key] = {}
|
30
38
|
end
|
31
39
|
area = area[key]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: structurebutcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miroslav Tynovsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|