sectionx 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d5ee09c486b5a7c78b44260bf1071e86755023de614c8202edf472bfb3bdecc
4
- data.tar.gz: 71812c5472522812adc526224cdffb83809361b1e99df823f1a7c8ec735996db
3
+ metadata.gz: b4e4ca9633bf1b35ddbbc560f96864c6006bdb82a350f5549fb61ab0802834e3
4
+ data.tar.gz: eb054954973c84726d483aaf11fa27715b3dc9b741d55f205006cc8371326dc7
5
5
  SHA512:
6
- metadata.gz: 2d11a4ebfe809cc64261a3a325e007defa0a4c2b0a46e17a9f754c91bcfc9aaba3e94f6dbb543c6f29c4d106451c398412225d6fba2c832a87a2f1d7d0025135
7
- data.tar.gz: fb00102a23afc8ec47cb1827397d7d7297c4ffaea188c4851a97ea203449605442f7e189a64942f0c856c9118b2a30412aad618920babe093b74b23dd53cc629
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
- xpath = "summary/" + h.keys.first.to_s
90
- puts 'xpath: ' + xpath.inspect if @debug
91
- e = @doc.root.element(xpath)
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
- e.text = h.values.first if e
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
- instance_eval "def #{name}() self.sections[:#{name}] end"
198
- r.merge(name.to_sym => SectionX.new(section, debug: @debug))
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sectionx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file