14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/sectionx.rb', line 14
def import(raw_s)
lines = raw_s.lines
= lines.shift
id = [/id=["']([^"']+)/,1] || 'sectionx'
body, summary = lines.join.strip.split(/^----*$/).reverse
nested = indent_heading("# summary\n%s\n# begin\n%s" % [summary,\
body.strip])
a = LineTree.new(nested).to_a
summary = a.shift.flatten(1)
summary.shift
section1 = a.shift.flatten(1)
section1.shift
xml = RexleBuilder.new
a2 = xml.send(id) do
xml.summary do
summary.each do |raw_x|
label, value = raw_x.split(/\s*:\s*/,2)
xml.send(label.downcase.gsub(/\s+/,'_'), value)
end
end
xml.sections do
xml.section do
xml.summary do
section1.each do |raw_x|
label, value = raw_x.split(/\s*:\s*/,2)
xml.send(label.downcase.gsub(/\s+/,'_'), value)
end
end
xml.sections
end
a.each do |section_name, raw_rows|
xml.section({title: section_name}) do
xml.summary do
raw_rows.each do |raw_x|
label, value = raw_x.split(/\s*:\s*/,2)
xml.send(label.downcase.gsub(/\s+/,'_'), value)
end
end
xml.sections
end
end
end
end
@doc = Rexle.new a2
end
|