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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/sectionx.rb', line 17
def import(raw_s)
raw_buffer, type = RXFHelper.read(raw_s)
lines = raw_buffer.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
xml.recordx_type 'sectionx'
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 = doc = Rexle.new a2
@summary = doc.root.xpath('summary/*')\
.inject({}) {|r,x| r.merge(x.name.to_sym => x.text)}
summary_methods = (@summary.keys - self.public_methods)
summary_methods.each do |x|
instance_eval "
def #{x.to_sym}()
@summary[:#{x}]
end
def #{x.to_s}=(v)
@summary[:#{x}] = v
@doc.root.element('summary/#{x.to_s}').text = v
end
"
end
self
end
|