kvx 0.1.2 → 0.2.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/kvx.rb +40 -2
- metadata +4 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d243a687afd8e0ad9bf8c4e7a38a6eedd02a9ef4
|
4
|
+
data.tar.gz: 90cba2e99e6138b1dd2932d265f1fd1c5fb972af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc950bc81d044d2d616733f3e95207dfc72b9236a1a411f5b41adaa5c0e0b64274fb064cb4e342b6b4704d1d5115eac58400b889d79d27843510b717a9acb0a9
|
7
|
+
data.tar.gz: ebdb9f57945a969d2a3a63a6b360608fb3922b4b9febbb6721811699a2822dd9cec0283e2aae59e4a451fc85bf9d621851d02b30687da1a99eb980c86fa92696
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/kvx.rb
CHANGED
@@ -20,6 +20,7 @@ class Kvx
|
|
20
20
|
def initialize(x, attributes: {})
|
21
21
|
|
22
22
|
@header = false
|
23
|
+
@identifier = 'kvx'
|
23
24
|
@attributes = attributes
|
24
25
|
h = {hash: :passthru, :'rexle::element' => :hashify, string: :parse_to_h}
|
25
26
|
@to_h = method(h[x.class.to_s.downcase.to_sym]).call x
|
@@ -29,6 +30,21 @@ class Kvx
|
|
29
30
|
def parse(t=nil)
|
30
31
|
parse_to_h(t || @to_s)
|
31
32
|
end
|
33
|
+
|
34
|
+
def to_s()
|
35
|
+
|
36
|
+
header = ''
|
37
|
+
|
38
|
+
if @header then
|
39
|
+
|
40
|
+
header = '<?' + @identifier
|
41
|
+
header += ' ' + @attributes.map {|x| "%s='%s'" % x }.join(' ')
|
42
|
+
header += "?>\n\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
header + scan_to_s(@to_h)
|
46
|
+
|
47
|
+
end
|
32
48
|
|
33
49
|
def to_xml(options={pretty: true})
|
34
50
|
|
@@ -87,8 +103,17 @@ class Kvx
|
|
87
103
|
a = s.strip.lines
|
88
104
|
|
89
105
|
txt = if a[0] =~ header_pattern then
|
90
|
-
|
91
|
-
|
106
|
+
|
107
|
+
raw_header = a.shift
|
108
|
+
attr = get_attributes(raw_header)
|
109
|
+
|
110
|
+
if attr[:created] then
|
111
|
+
attr[:last_modified] = Time.now.to_s
|
112
|
+
else
|
113
|
+
attr[:created] = Time.now.to_s
|
114
|
+
end
|
115
|
+
|
116
|
+
@attributes.merge! attr
|
92
117
|
@header = true
|
93
118
|
a.join
|
94
119
|
else
|
@@ -174,5 +199,18 @@ class Kvx
|
|
174
199
|
end
|
175
200
|
|
176
201
|
end
|
202
|
+
|
203
|
+
def scan_to_s(h, indent='')
|
204
|
+
|
205
|
+
a = h.inject([]) do |r, x|
|
206
|
+
if x.last.is_a? Hash then
|
207
|
+
r << x.first.to_s + ":\n" + scan_to_s(x.last, ' ')
|
208
|
+
else
|
209
|
+
r << "%s%s: %s" % [indent, *x]
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
@to_s = a.join("\n")
|
214
|
+
end
|
177
215
|
|
178
216
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kvx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
Vo86eJaJUXJbywrm97pYB2utyzWPyxJihIh0eFuNbCk+XOWfv6vUEyuXMiCsiyrF
|
32
32
|
azRHJ6uLeQu4hw==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-04-
|
34
|
+
date: 2015-04-28 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: line-tree
|
@@ -103,5 +103,6 @@ rubyforge_project:
|
|
103
103
|
rubygems_version: 2.4.6
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
|
-
summary:
|
106
|
+
summary: Kvx (Keys, Attributes, and XML) makes it convenient to store and retrieve
|
107
|
+
the simplest of data as plain text using a hash-like format or as XML.
|
107
108
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|