sectionx 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86aee6fa7596e7802019252d40920e6929fa4392
4
- data.tar.gz: 2409e37c1fd6bc756c6680239d7aacc139c07128
3
+ metadata.gz: 18ba024193f2b8e20e98abdbc95a62066b7225a9
4
+ data.tar.gz: 3657688b3c3ad30593a5f140b53d7eee9c353ca5
5
5
  SHA512:
6
- metadata.gz: 0cd016c86aa9fd9ce8a5f7d4c911eb2c030c6df7493cbff3f2ddc8ff94ea0bcda7a1e0a8a2bbe7df4094859732a708838ae9496a8c51e0abb819764a124acf4a
7
- data.tar.gz: b1de0c2038dd999c274a92ca62f9716f67858909a025faa320f7c12b54269891d6d2df53827c560e87ce792dbd0c7635db1c993ea2b25aef97a6fa65625067f2
6
+ metadata.gz: 5b5cbc940c639cc7a79829d811f0cc2eb9660923e314e45c0c939332387aff154bcf71e16e8a8f780fdffac6e468224be852e16bc03191a83d8421615f95423e
7
+ data.tar.gz: dcb5ea50fa71f42603c7c94759e40be38be0d22daed0cd845765b9bb3d907abcdd6e6a9266fe6549cfd49de8d51087dd6c82aa347eef361796fac05d8c10e1d3
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/sectionx.rb CHANGED
@@ -12,10 +12,16 @@ class SectionX
12
12
 
13
13
  attr_reader :summary, :sections
14
14
 
15
- def initialize(e=nil)
15
+ def initialize(x=nil)
16
16
 
17
- if e then
18
- @summary, @sections = parse_root_node e
17
+ @doc = if x.is_a? String then
18
+ buffer, _ = RXFHelper.read x
19
+ Rexle.new buffer
20
+ elsif x.is_a? Rexle::Element then x
21
+ end
22
+
23
+ if @doc then
24
+ @summary, @sections = parse_root_node @doc.root
19
25
  end
20
26
  end
21
27
 
@@ -48,7 +54,7 @@ class SectionX
48
54
 
49
55
  a2 = xml.send(id) do
50
56
  xml.summary do
51
- summary.each {|label, value| xml.send(label, value) }
57
+ summary.each {|label, value| xml.send(label, escape(value)) }
52
58
  xml.recordx_type 'sectionx'
53
59
  end
54
60
  xml.sections do
@@ -56,7 +62,7 @@ class SectionX
56
62
  xml.summary do
57
63
  section1.each do |raw_x|
58
64
  label, value = raw_x.split(/\s*:\s*/,2)
59
- xml.send(label.downcase.gsub(/\s+/,'_'), value)
65
+ xml.send(label.downcase.gsub(/\s+/,'_'), escape(value))
60
66
  end
61
67
  end
62
68
  xml.sections
@@ -66,7 +72,7 @@ class SectionX
66
72
  xml.summary do
67
73
  raw_rows.each do |raw_x|
68
74
  label, value = raw_x.split(/\s*:\s*/,2)
69
- xml.send(label.downcase.gsub(/\s+/,'_'), value)
75
+ xml.send(label.downcase.gsub(/\s+/,'_'), escape(value))
70
76
  end
71
77
  end
72
78
  xml.sections
@@ -75,26 +81,9 @@ class SectionX
75
81
  end
76
82
  end
77
83
 
78
- @doc = doc = Rexle.new a2
79
-
80
- @summary, @sections = parse_root_node(doc.root)
81
-
82
- summary_methods = (summary.keys - self.public_methods)
84
+ @doc = Rexle.new a2
85
+ @summary, @sections = parse_root_node(@doc.root)
83
86
 
84
- summary_methods.each do |x|
85
-
86
- instance_eval "
87
-
88
- def #{x.to_sym}()
89
- @summary[:#{x}]
90
- end
91
-
92
- def #{x.to_s}=(v)
93
- @summary[:#{x}] = v
94
- @doc.root.element('summary/#{x.to_s}').text = v
95
- end
96
- "
97
- end
98
87
  self
99
88
  end
100
89
 
@@ -122,7 +111,10 @@ class SectionX
122
111
 
123
112
  private
124
113
 
125
-
114
+ def escape(v)
115
+ v.gsub('&','&amp;').gsub('<','&lt;').gsub('>','&gt;')
116
+ end
117
+
126
118
  def indent_heading(s, heading='#')
127
119
 
128
120
  a = s.split(/(?=^\s*#{heading}\s*\w)/).map do |x|
@@ -148,6 +140,22 @@ class SectionX
148
140
  def parse_root_node(e)
149
141
 
150
142
  summary = RecordX.new e.xpath('summary/*')
143
+ summary_methods = (summary.keys - self.public_methods)
144
+
145
+ summary_methods.each do |x|
146
+
147
+ instance_eval "
148
+
149
+ def #{x.to_sym}()
150
+ @summary[:#{x}]
151
+ end
152
+
153
+ def #{x.to_s}=(v)
154
+ @summary[:#{x}] = v
155
+ @doc.root.element('summary/#{x.to_s}').text = v
156
+ end
157
+ "
158
+ end
151
159
 
152
160
  sections = e.xpath('sections/section').map do |section|
153
161
  SectionX.new section
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sectionx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file