sectionx 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/sectionx.rb +30 -8
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4e4ca9633bf1b35ddbbc560f96864c6006bdb82a350f5549fb61ab0802834e3
|
4
|
+
data.tar.gz: eb054954973c84726d483aaf11fa27715b3dc9b741d55f205006cc8371326dc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c5bec2f043a19f857bdae0e75c2abe84724b7588b1bf3e7473c587820f907770a573022c08e86814b3e55ba380fa242671ce9fe4b8d0d9b5ecece93d4a02a7c
|
7
|
+
data.tar.gz: ce808ee0bd8b3af833821dd2a75f29bc601251e8976b4f01ad29b79d155d79049d8e98459838fe168d1add8072d24372b98cbbaa80d5634cfa51a879a008939c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/sectionx.rb
CHANGED
@@ -15,6 +15,7 @@ class SectionX
|
|
15
15
|
def initialize(x=nil, debug: false)
|
16
16
|
|
17
17
|
@debug = debug
|
18
|
+
puts 'initialize() x: ' + x.inspect if @debug
|
18
19
|
|
19
20
|
@doc = if x.is_a? String then
|
20
21
|
buffer, _ = RXFHelper.read x
|
@@ -71,6 +72,19 @@ class SectionX
|
|
71
72
|
self
|
72
73
|
end
|
73
74
|
|
75
|
+
def new_section(raw_title)
|
76
|
+
|
77
|
+
doc = Rexle.new("<section title='#{raw_title}'><summary/>" +
|
78
|
+
"<sections/></section>")
|
79
|
+
@doc.root.element('sections').add doc.root
|
80
|
+
title = raw_title.gsub(/\s+/,'_').downcase.to_sym
|
81
|
+
@sections[title] = SectionX.new \
|
82
|
+
@doc.root.element('sections').elements.last, debug: @debug
|
83
|
+
|
84
|
+
define_singleton_method(title) { self.sections[title] }
|
85
|
+
|
86
|
+
end
|
87
|
+
|
74
88
|
def recordx_type()
|
75
89
|
@summary[:recordx_type]
|
76
90
|
end
|
@@ -86,11 +100,18 @@ class SectionX
|
|
86
100
|
def update(id=nil, h={})
|
87
101
|
|
88
102
|
puts 'inside update h: ' + h.inspect if @debug
|
89
|
-
|
90
|
-
|
91
|
-
|
103
|
+
summary = @doc.root.element('summary')
|
104
|
+
name = h.keys.first.to_s
|
105
|
+
puts 'xpath: ' + name.inspect if @debug
|
106
|
+
e = summary.element(name)
|
92
107
|
puts 'e: ' + e.inspect if @debug
|
93
|
-
|
108
|
+
|
109
|
+
if e then
|
110
|
+
e.text = h.values.first
|
111
|
+
else
|
112
|
+
summary.add Rexle::Element.new(name).add_text(h.values.first)
|
113
|
+
end
|
114
|
+
|
94
115
|
puts '@doc: ' + @doc.xml if @debug
|
95
116
|
end
|
96
117
|
|
@@ -180,7 +201,7 @@ class SectionX
|
|
180
201
|
|
181
202
|
a = e.xpath('sections/section')
|
182
203
|
|
183
|
-
return [attributes, summary] if a.empty?
|
204
|
+
return [attributes, summary, {}] if a.empty?
|
184
205
|
|
185
206
|
sections = {}
|
186
207
|
|
@@ -192,10 +213,11 @@ class SectionX
|
|
192
213
|
sections = a.inject(sections) do |r, section|
|
193
214
|
|
194
215
|
h = section.attributes
|
195
|
-
name = (h[:id] || h[:title].gsub(/\s+/,'_')).downcase
|
216
|
+
name = (h[:id] || h[:title].gsub(/\s+/,'_')).downcase.to_sym
|
196
217
|
|
197
|
-
|
198
|
-
|
218
|
+
obj_section = SectionX.new(section, debug: @debug)
|
219
|
+
define_singleton_method(name) { obj_section }
|
220
|
+
r.merge(name => obj_section)
|
199
221
|
end
|
200
222
|
|
201
223
|
[attributes, summary, sections]
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|