kvx 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +1 -0
- data/lib/kvx.rb +168 -0
- metadata +107 -0
- metadata.gz.sig +1 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 817907abde6224e0927fadce5e3b6ff45bf170a5
|
4
|
+
data.tar.gz: 745afaaf9215927f7c19e739d39f9f27921e92dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b7bb78ebed825fdb6fbd24bc2ba7e06ad1f8484508c11ebe3a464f49eaa1ba1a3447380940d3f769b18408397a02e4337479ef336b932211d9f0657642b0d5e
|
7
|
+
data.tar.gz: 479af80eead59e44f79dee501438d036e9504db8af590981b97dd0793a0609d9a4a12358ab1be5ee646dc77a4cceda5c1feca5c13ac76d36a14a27eb6aecd6cc
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
54y�0\F|[���a���-����1�X3o���|C�=߈�e��1t�<���̙�03�Bf�'�l���!�����\������� eK\9�A�^̸{���~o����Xȃ�@�?'<T״R9-��9`����������������SQF'���+uO���~��$���`��wbL��X�;�^�7��D�d�)�$�t�)Y;K�u;�+��=��OQp`��d���p��j6�m�~�*��'�|
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�{�J��O �q�Y�Ёng�s���6�]`�����6�E��J��{�>mc�T|w��(}r=x�����B���댱9r�)�B<V��v�s�����X @�����%��v��I�,�]WO(�1�i�4�N-�� ����n]yGl��Ҙ��!W������Ğ�!�Ys�d��[W#�B���G��Շ,��f�I>$�2U��q^g��J1��]nj$y�D�~`�U�^��ϟ�B1�e��!��ign
|
data/lib/kvx.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
!#/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: kvx.rb
|
4
|
+
|
5
|
+
require 'line-tree'
|
6
|
+
require 'rxfhelper'
|
7
|
+
|
8
|
+
###
|
9
|
+
# Kvx does the following:
|
10
|
+
#
|
11
|
+
# * h -> xml
|
12
|
+
# * xml -> h
|
13
|
+
# * s -> h
|
14
|
+
|
15
|
+
class Kvx
|
16
|
+
|
17
|
+
attr_accessor :attributes
|
18
|
+
attr_reader :to_h
|
19
|
+
|
20
|
+
def initialize(x, attributes: {})
|
21
|
+
|
22
|
+
@attributes = attributes
|
23
|
+
h = {hash: :passthru, rexle: :hashify, string: :parse_to_h}
|
24
|
+
@to_h = method(h[x.class.to_s.downcase.to_sym]).call x
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse(t=nil)
|
29
|
+
parse_to_h(t || @to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_xml(options={pretty: true})
|
33
|
+
|
34
|
+
make_xml(@to_h)
|
35
|
+
|
36
|
+
a = [self.class.to_s.downcase, @attributes, '', *make_xml(@to_h)]
|
37
|
+
Rexle.new(a).xml(options)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def get_attributes(raw_attributes)
|
44
|
+
|
45
|
+
r1 = /([\w\-:]+\='[^']*)'/
|
46
|
+
r2 = /([\w\-:]+\="[^"]*)"/
|
47
|
+
|
48
|
+
r = raw_attributes.scan(/#{r1}|#{r2}/).map(&:compact)\
|
49
|
+
.flatten.inject(Attributes.new) do |r, x|
|
50
|
+
attr_name, raw_val = x.split(/=/,2)
|
51
|
+
val = attr_name != 'class' ? raw_val[1..-1] : raw_val[1..-1].split
|
52
|
+
r.merge(attr_name.to_sym => val)
|
53
|
+
end
|
54
|
+
|
55
|
+
return r
|
56
|
+
end
|
57
|
+
|
58
|
+
def hashify(e)
|
59
|
+
|
60
|
+
v = if e.has_elements? then
|
61
|
+
e.elements.inject({}) do |r, x|
|
62
|
+
r.merge hashify(x)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
e.text
|
66
|
+
end
|
67
|
+
|
68
|
+
{e.name => v}
|
69
|
+
end
|
70
|
+
|
71
|
+
def make_xml(h)
|
72
|
+
|
73
|
+
h.map do |name, x|
|
74
|
+
|
75
|
+
value = x.is_a?(Hash) ? make_xml(x) : x
|
76
|
+
[name, {}, *value]
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def parse_to_h(s, header_pattern=%r(^<\?kvx[\s\?]))
|
82
|
+
|
83
|
+
raw_txt, _ = RXFHelper.read(s)
|
84
|
+
|
85
|
+
# does the raw_txt contain header information?
|
86
|
+
a = s.strip.lines
|
87
|
+
|
88
|
+
txt = if a[0] =~ header_pattern then
|
89
|
+
raw_header = a.shift
|
90
|
+
@attributes.merge! get_attributes(raw_header)
|
91
|
+
@header = true
|
92
|
+
a.join
|
93
|
+
else
|
94
|
+
raw_txt
|
95
|
+
end
|
96
|
+
|
97
|
+
scan_to_h(txt)
|
98
|
+
end
|
99
|
+
|
100
|
+
def passthru(x)
|
101
|
+
x
|
102
|
+
end
|
103
|
+
|
104
|
+
def scan_to_h(txt)
|
105
|
+
|
106
|
+
raw_a = LineTree.new(txt.gsub(/(^-*$)|(#.*)/,'').strip,
|
107
|
+
ignore_blank_lines: false).to_a
|
108
|
+
|
109
|
+
# if there are any orphan lines which aren't nested underneath a
|
110
|
+
# label, they will be fixed using the following statement
|
111
|
+
|
112
|
+
a = raw_a.chunk {|x| x[0][/^\w+:|.*/]}.inject([]) do |r,y|
|
113
|
+
if r.last and !y.first[/\w+:/] then
|
114
|
+
r.last << y.last[-1]
|
115
|
+
else
|
116
|
+
r << y.last[-1]
|
117
|
+
end
|
118
|
+
r
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
@to_h = a.inject({}) do |r, line|
|
123
|
+
|
124
|
+
s = line.shift
|
125
|
+
|
126
|
+
|
127
|
+
if line.join.length > 0 then
|
128
|
+
|
129
|
+
r2 = if line[0][0][/^\w+: /] then
|
130
|
+
|
131
|
+
scan_to_h(line.join("\n"))
|
132
|
+
|
133
|
+
else
|
134
|
+
|
135
|
+
desc = pretty_print(line).split(/\n(?=\w+: )/)
|
136
|
+
|
137
|
+
txt2, remaining = desc
|
138
|
+
|
139
|
+
h = txt2.lines.inject([]) do |r, x|
|
140
|
+
x.chomp!
|
141
|
+
x.length > 0 ? r << x : r
|
142
|
+
end
|
143
|
+
|
144
|
+
r3 = {description: txt2, items: h}
|
145
|
+
|
146
|
+
if remaining then
|
147
|
+
|
148
|
+
r3.merge!(scan_to_h remaining + "\n ")
|
149
|
+
end
|
150
|
+
|
151
|
+
r3
|
152
|
+
end
|
153
|
+
|
154
|
+
r.merge({s[/[^:]+/].to_sym => r2})
|
155
|
+
|
156
|
+
else
|
157
|
+
|
158
|
+
value, name = s.split(': ',2).reverse
|
159
|
+
name ||= 'description'
|
160
|
+
|
161
|
+
r.merge({name.to_sym => value.to_s})
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kvx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTE1MDQyNDA5MDczNFoXDTE2MDQyMzA5MDczNFowSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17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JihIh0eFuNbCk+XOWfv6vUEyuXMiCsiyrF
|
32
|
+
azRHJ6uLeQu4hw==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: line-tree
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.5'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.5.0
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.5'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.5.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rxfhelper
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.1'
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.1.12
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0.1'
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.12
|
76
|
+
description:
|
77
|
+
email: james@r0bertson.co.uk
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- lib/kvx.rb
|
83
|
+
homepage: https://github.com/jrobertson/kvx
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.4.6
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: kvx
|
107
|
+
test_files: []
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�#�TY�cj����g�=��xF\-��k��wO�s�=>�y��X*��#=/+F
|