kvx 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +3 -2
  3. data.tar.gz.sig +0 -0
  4. data/lib/kvx.rb +44 -19
  5. metadata +8 -8
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b505b5c13d62100140d9c7cdd00772fcdda1be48
4
- data.tar.gz: 2ceec413f42836ad5e21fa39868ddd5e4bcd5498
3
+ metadata.gz: 9a5ce44df5b7814c9771fe7f02e068759efd213a
4
+ data.tar.gz: add78d344d8b9c5773e00752efc6311e7f56aaef
5
5
  SHA512:
6
- metadata.gz: b9c99fc02d2243c0dad0de86ce83c562b96cdb39b13577b7529cfd07405bd90e4bcb02a2de540cc78da40faf26a9e455d5ea73d4a73f884754d62fa92b77c9a2
7
- data.tar.gz: f2a95a0abd526045bdff0b5703fb65d2c87f895ef04c1aa8ed6547f4b0bbc5610488c38f058e4a2258fb4e8d1a64646617e065c19b29cd59cbf1bcc5ea2e9204
6
+ metadata.gz: a8ba4b20ca846227f4ed6b25cde698e5dee776ec788cd3e844d693876e1d763faff51b9168e19cec5c36740defbd2dd03c4a75b31e60436fb72f7119690e62ca
7
+ data.tar.gz: a77121149530bd9f72c72a519f47e929ebe3a72378d40593f89a7dc88bc2d2f7fbd8b5cb6fd548312f790fcc14933c6fce0f2b2ec00a66d0afb0b0b6efa988a6
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- R�/Af_�%s���@��l���-�HWrt��qH�2�/��oc�ᇜm;���Q7lX�`�ˮ������if��=��âv�it���4o\�OO^
2
- pBR�ʔ���so��:\Q���L��#���W��wh���b����C���V*� ��Q��� -�й����L�ms?T{\�����̒+tة `��G��d_�j�z==A�jw��fR�)�%��R�rJ>hѶHM�EJ#� q+YQ��0:
1
+ g�ɕn��jY)cݤ~и�J�����˾B�������T7�����Y���B�LTb�|:rΊֶ����^ W�e�`%ǡk4���CT���#2���r�G3q$�!�ԥ:e���ߗ��ðgrg��6��X��0&���� [_�� ��`��f�D0�_n��c���\2�D_�.�����s) �>YE4.��@�KY`4LW}n�
2
+ ��?kʶ��˺Mؒ����pY#
3
+ A��cᝮ�RM0
data.tar.gz.sig CHANGED
Binary file
data/lib/kvx.rb CHANGED
@@ -14,48 +14,59 @@ require 'rxfhelper'
14
14
 
15
15
  class Kvx
16
16
 
17
- attr_accessor :attributes
17
+ attr_accessor :attributes, :summary
18
18
  attr_reader :to_h
19
19
 
20
20
  def initialize(x, attributes: {})
21
-
21
+
22
22
  @header = false
23
23
  @identifier = 'kvx'
24
+ @summary = {}
24
25
  @attributes = attributes
25
- h = {hash: :passthru, :'rexle::element' => :hashify, string: :parse_string}
26
- @h = method(h[x.class.to_s.downcase.to_sym]).call x
26
+
27
+ h = {
28
+ hash: :passthru,
29
+ :'rexle::element' => :xml_to_h,
30
+ string: :parse_string
31
+ }
32
+
33
+ @body = method(h[x.class.to_s.downcase.to_sym]).call x
27
34
 
28
35
  end
29
36
 
30
37
  def item()
31
- @h
38
+ @body
32
39
  end
33
40
 
41
+ alias body item
42
+
34
43
  def to_h()
35
- deep_clone @h
44
+ deep_clone @body
36
45
  end
37
46
 
38
47
  def to_s()
39
48
 
40
49
  header = ''
41
50
 
42
- if @header then
51
+ if @header or @summary then
43
52
 
53
+ attr = @attributes ? @attributes.map {|x| "%s='%s'" % x }.join(' ') : ''
44
54
  header = '<?' + @identifier
45
- header += ' ' + @attributes.map {|x| "%s='%s'" % x }.join(' ')
55
+ header += attr
46
56
  header += "?>\n"
57
+ header += scan_to_s @summary
58
+ header += "\n----------------------------------\n\n"
47
59
  end
48
- h = @to_h
49
60
 
50
- header + scan_to_s(@to_h)
61
+ header + scan_to_s(@body)
51
62
 
52
63
  end
53
64
 
54
65
  def to_xml(options={pretty: true})
55
-
56
- make_xml(@to_h)
57
-
58
- a = [self.class.to_s.downcase, @attributes, '', *make_xml(@to_h)]
66
+
67
+ summary = [:summary, {}, *make_xml(@summary)]
68
+ body = [:body, {}, *make_xml(@body)]
69
+ a = [self.class.to_s.downcase, @attributes, '', summary, body]
59
70
  Rexle.new(a).xml(options)
60
71
 
61
72
  end
@@ -101,7 +112,7 @@ class Kvx
101
112
  e.text
102
113
  end
103
114
 
104
- {e.name => v}
115
+ {e.name.to_sym => v}
105
116
  end
106
117
 
107
118
  def make_xml(h)
@@ -117,7 +128,7 @@ class Kvx
117
128
  def parse_string(s)
118
129
 
119
130
  buffer, type = RXFHelper.read(s)
120
- type == :xml ? hashify(buffer) : parse_to_h(buffer)
131
+ type == :xml ? xml_to_h(Rexle.new(buffer).root) : parse_to_h(buffer)
121
132
 
122
133
  end
123
134
 
@@ -141,7 +152,10 @@ class Kvx
141
152
 
142
153
  @attributes.merge! attr
143
154
  @header = true
144
- a.join
155
+ body, summary = a.join.strip.split(/^----*$/).reverse
156
+ @summary = scan_to_h summary
157
+
158
+ body
145
159
  else
146
160
  raw_txt
147
161
  end
@@ -180,7 +194,7 @@ class Kvx
180
194
  end
181
195
 
182
196
 
183
- @to_h = a.inject({}) do |r, line|
197
+ @body = a.inject({}) do |r, line|
184
198
 
185
199
  s = line.shift
186
200
 
@@ -237,6 +251,17 @@ class Kvx
237
251
  end
238
252
 
239
253
  @to_s = a.join("\n")
240
- end
254
+ end
255
+
256
+ def xml_to_h(node)
257
+
258
+ summary = node.element('summary')
259
+ if summary then
260
+ @summary = hashify(summary)[:summary]
261
+ @body = hashify(node.element('body'))[:body]
262
+ else
263
+ @body = hashify node
264
+ end
265
+ end
241
266
 
242
267
  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.3.0
4
+ version: 0.4.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-28 00:00:00.000000000 Z
34
+ date: 2015-04-29 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: line-tree
@@ -42,7 +42,7 @@ dependencies:
42
42
  version: '0.5'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 0.5.0
45
+ version: 0.5.3
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,27 +52,27 @@ dependencies:
52
52
  version: '0.5'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 0.5.0
55
+ version: 0.5.3
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rxfhelper
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0.1'
62
+ version: '0.2'
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 0.1.12
65
+ version: 0.2.3
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '0.1'
72
+ version: '0.2'
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.12
75
+ version: 0.2.3
76
76
  description:
77
77
  email: james@r0bertson.co.uk
78
78
  executables: []
metadata.gz.sig CHANGED
Binary file