structurebutcher 0.3.0 → 0.4.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/structurebutcher.rb +10 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a99db9d04f702bb44f5c57cf78854c348cb9f39e
4
- data.tar.gz: 5fb7630a82a66c40af57fd743201dab002711ce5
3
+ metadata.gz: 2f8a698fe9243394623cc78e9d4615c763754ba6
4
+ data.tar.gz: e82e5c52fff3d88627cfecab4d86119c67687c3e
5
5
  SHA512:
6
- metadata.gz: a5153756f0c7fa0b3045efa4fd53443e0380aa6301eb91bb5d7cda82b8bc8c632b77cdf04385989f11871ac19d3f3150e04efcfd28d4a8d9a748f089f4370135
7
- data.tar.gz: 8913a701324f13fc6f2025eeb2b6766d4462ae0ab975235494e959e82f647a177a63a021b3dd780e9db654193f0d02f0a7625700a420652fcccb57d0d18e0c7e
6
+ metadata.gz: 2bae99c1382dd400295eb3837abd3cc1323be2d8f907fca289d0b35eca0dba24b2857d587246ecde1a5dd856a6b0ee274af5ec04adc04507d06d8b5c2c677628
7
+ data.tar.gz: ca00617bce45de9ee8bf81ab2ab8244e0dfdc74d224ae07fc4893369aacbd1bb68f4d77bcd4aafff42848a511bd30c614495ff4b26c672c21ab122296210022a
@@ -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.split('.')
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.3.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-10-14 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json