xml-registry 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e49bef3fd75dd4915a13fafb8323f237e09843f
4
- data.tar.gz: 2219b82b077216d24989793bc941cb5669741b64
3
+ metadata.gz: d340a550aa48a3f5fa2303c0265eb0d9d950966f
4
+ data.tar.gz: 8426520b1cdd99fe9d55129e7f2524fa8ec1c853
5
5
  SHA512:
6
- metadata.gz: ef309b0c7e11bf75ccc9ad180a592b2b7b1ca9b392244ee11f10abdf2bc0d94bae06e167f6c44956d562038d2c583f1bb1405f0d90a4ef9aac590a893011b418
7
- data.tar.gz: a7d79c4d122a5b83361ac0a5138e5374414a0de243f7f66be3196a89abd4bd2447887886dcbd485a36117a23f3aa4b2d8a1650683a7bf136632635a5d44b7178
6
+ metadata.gz: b7db78c63204b32540ea16516e45b545f0280b098b42de9a7bb32fb976830139ab3e192b2ac8065e34c8d70d1d8146884d80028c373df38d0e39435fd97b3db5
7
+ data.tar.gz: 37d2b6de36e8b614c687be60866e7a1ab55818898aad0bbe932b1e4427e06feff2b2fa0c7a0c9b72afc81bf00016ba3bef1780dff02ceccce3d88b7b4fa9aa70
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/xml-registry.rb CHANGED
@@ -7,7 +7,19 @@
7
7
  require 'simple-config'
8
8
 
9
9
 
10
+ module NumberCheck
11
+
12
+ refine String do
13
+
14
+ def is_number?
15
+ self.to_i.to_s == self
16
+ end
17
+
18
+ end
19
+ end
20
+
10
21
  class XMLRegistry
22
+ using NumberCheck
11
23
 
12
24
  attr_reader :doc
13
25
 
@@ -34,22 +46,20 @@ class XMLRegistry
34
46
 
35
47
  # if the 1st element doesn't exist create it
36
48
  e = path.split('/',2).first
37
-
38
49
  @doc.root.add_element Rexle::Element.new(e) unless @doc.root.element e
39
50
  create_path = find_path(path)
40
-
41
- if not create_path.empty? then
42
51
 
43
- a = path.split('/').map {|x| x.to_i.to_s == x ? x.prepend('x') : x}
44
- parent_path = (a - create_path.reverse).join('/')
52
+ if not create_path.empty? then
53
+ parent_path = (path.split('/') - create_path.reverse).join('/')
45
54
  key_builder(parent_path, create_path)
46
55
  end
47
-
56
+
48
57
  add_value(path, value)
49
58
  end
50
59
 
51
60
  def []=(path, val)
52
- self.set_key(path, val)
61
+ s = path.split('/').map {|x| x.is_number? ? x.prepend('x') : x}.join '/'
62
+ self.set_key(s, val)
53
63
  end
54
64
 
55
65
  # get the key value by passing the path
@@ -100,7 +110,8 @@ class XMLRegistry
100
110
  end
101
111
 
102
112
  def [](path)
103
- @doc.root.element path
113
+ s = path.split('/').map {|x| x.is_number? ? x.prepend('x') : x}.join '/'
114
+ @doc.root.element s
104
115
  end
105
116
 
106
117
  # delete the key at the specified path
@@ -202,28 +213,20 @@ class XMLRegistry
202
213
  private
203
214
 
204
215
  def add_key(path='app', key='untitled')
205
-
206
216
  node = @doc.root.element path
207
217
  r = node.add_element Rexle::Element.new(key)
208
218
  r
209
-
210
219
  end
211
220
 
212
221
  def add_value(key, value)
213
- s = key.split('/').map {|x| x.to_i.to_s == x ? x.prepend('x') : x}.join '/'
214
- @doc.root.element(s).text = value
222
+ @doc.root.element(key).text = value
215
223
  end
216
224
 
217
225
  def find_path(path, create_path=[])
218
226
 
219
227
  return create_path if !@doc.root.xpath(path).empty?
220
228
  apath = path.split('/')
221
-
222
- x = apath.pop
223
-
224
- x.prepend 'x' if x.to_i.to_s == x
225
- create_path << x
226
-
229
+ create_path << apath.pop
227
230
  find_path(apath.join('/'), create_path)
228
231
  end
229
232
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file