mindwords 0.3.0 → 0.5.0

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: 2cff4e2c8dbff0eee0e0e4fa8fe0411d84d772e4348aca0eef1585e64887a4c2
4
- data.tar.gz: 434d7757907e356ce733a1ab1f81a185677bd580ac9bb56c288b821adac2508c
3
+ metadata.gz: 318da7a9e4daf9a4f4d69d4315d062fab0f4b2876c3a0302a86d4d1b40909a32
4
+ data.tar.gz: cd0336cf0a70c0e90fec5964f5a987cbad0abb9e295fc96ddf54a6999832af91
5
5
  SHA512:
6
- metadata.gz: 2443f5089c5b27b799a0c9d9c059a8157817f16bc82ffe2e868c60fa3b55c1fdf27778e8a064b4d48e8a8bf671845010ab3ab08d5481d924626f38b2861ba369
7
- data.tar.gz: daac6e6f0b0a4be3dbd664eb9c1e2e489b29b1435b4ec0e507fd35f4224d51d7b79073d2ca21e5ed836a1c7fd4886ef28b2883cf515bf9789bedbb7c171dcdfb
6
+ metadata.gz: 1eb530ac7ff6db8b68e2827c51a7ad4ed0ed7244340e842b6ff967c2da1f32a777fff8fc2ddc91d3d04380d0e045cb9d468eba883bf064c8dd00f4686af064e2
7
+ data.tar.gz: 41708695837cfdc20e091889d88bb1d4e1d8a8c564855f5dbd75f640fc773ffd080353c30f073e4bbb8f76ff5e2ebefccc99a7272d55992358e22f4c8e9984ed
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -3,6 +3,7 @@
3
3
  # file: mindwords.rb
4
4
 
5
5
  require 'rexle'
6
+ require 'rxfhelper'
6
7
  require 'line-tree'
7
8
 
8
9
  module HashCopy
@@ -20,9 +21,11 @@ class MindWords
20
21
  using HashCopy
21
22
 
22
23
 
23
- def initialize(s, parent: nil, debug: false)
24
+ def initialize(raws, parent: nil, debug: false)
24
25
 
25
26
  @debug = debug
27
+
28
+ s, _ = RXFHelper.read raws
26
29
  @a = s.strip.gsub(/^\n/,'').lines
27
30
  @a.shift if @a.first =~ /<\?mindwords\?>/
28
31
 
@@ -47,24 +50,25 @@ class MindWords
47
50
 
48
51
  @hashtags = h.deep_clone.sort.map {|tag, fields| [tag, fields.sort]}.to_h
49
52
 
50
- # does the key exist as a field? Nesting of hash object is performed here.
51
-
52
- h.keys.each do |key|
53
-
54
- r = h.detect {|_, value| value.include? key}
55
- next unless r
56
- h[r.first].delete key
57
- h[r.first] << {key => h[key]}
58
- #puts r.inspect
59
- h.delete key
60
-
61
- end
62
-
63
- @h = h
64
53
 
65
54
  a = rexlize(h)
66
55
  doc = Rexle.new(['root', {}, '', *a])
67
56
 
57
+ # apply node nesting
58
+
59
+ doc.root.elements.each do |e|
60
+
61
+ doc.root.xpath('//' + e.name).each do |e2|
62
+
63
+ next if e2 === e
64
+
65
+ e2.parent.add e
66
+ e2.delete
67
+
68
+ end
69
+
70
+ end
71
+
68
72
 
69
73
  # remove duplicates which appear in the same branch above the nested node
70
74
  rm_duplicates(doc)
@@ -83,7 +87,7 @@ class MindWords
83
87
  end
84
88
 
85
89
  redundants.compact.each {|x| doc.element(x).delete }
86
- rm_duplicates(doc)
90
+
87
91
 
88
92
  node = if parent then
89
93
  found = doc.root.element('//' + parent)
@@ -95,6 +99,8 @@ class MindWords
95
99
  @outline = treeize node
96
100
 
97
101
  node.root.each_recursive do |e|
102
+
103
+ e.attributes[:id] = e.attributes[:title].downcase.gsub(/ +/,'-')
98
104
 
99
105
  s = e.parent.attributes[:breadcrumb] ? \
100
106
  e.parent.attributes[:breadcrumb].to_s + ' / ' : ''
@@ -103,7 +109,7 @@ class MindWords
103
109
  r = @a.grep(/^#{e.attributes[:title]} #/i)
104
110
  next unless r.any?
105
111
  e.attributes[:hashtags] = r[0].scan(/(?<=#)\w+/).join(' ')
106
- e.attributes[:id] = e.attributes[:title].downcase.gsub(/ +/,'-')
112
+
107
113
 
108
114
  end
109
115
 
@@ -208,7 +214,7 @@ class MindWords
208
214
  end
209
215
 
210
216
  def to_words()
211
- to_outline.lines.map {|x| x[/\w[\w ]+/] }
217
+ to_outline.lines.map {|x| x[/\w[\w ]+/] }.uniq
212
218
  end
213
219
 
214
220
  def to_xml()
@@ -225,16 +231,19 @@ class MindWords
225
231
 
226
232
  case x
227
233
  when String
228
- [x.gsub(/ +/,'_'), {title: x}, x]
234
+ [x.downcase.gsub(/ +/,''), {title: x}, x]
229
235
  when Hash
230
236
  [
231
- x.keys.first.gsub(/_/,' '),
237
+ x.keys.first.downcase.gsub(/_/,' '),
232
238
  {title: x.keys.first},
233
239
  x.keys.first,
234
240
  *rexlize(x.values.first)
235
241
  ]
236
242
  when Array
237
- [x.first.gsub(/_/,' '), {title: x.first}, x.first, *rexlize(x.last)]
243
+ [
244
+ x.first.downcase.gsub(/_/,' '),
245
+ {title: x.first}, x.first, *rexlize(x.last)
246
+ ]
238
247
  end
239
248
  end
240
249
 
@@ -243,24 +252,22 @@ class MindWords
243
252
  def rm_duplicates(doc)
244
253
 
245
254
  duplicates = []
255
+
246
256
  doc.root.each_recursive do |e|
247
257
 
248
- puts 'e: ' + e.name.inspect if @debug
249
258
  rows = e.parent.xpath('//' + e.name)
250
259
  next if rows.length < 2
251
260
 
252
- rows[1..-1].each do |e2|
253
- puts 'e2: ' + e2.name.inspect if @debug
254
- duplicates << [e.backtrack.to_s, e2.backtrack.to_s]
255
- end
261
+ rows[0..-2].each {|e2| duplicates << e.backtrack.to_s }
262
+
256
263
  end
257
264
 
258
- duplicates.each do |path, oldpath|
259
- e = doc.element(path);
260
- e2 = doc.element(oldpath);
261
- next unless e2
262
- e2.parent.add e
263
- e2.delete
265
+ duplicates.each do |path|
266
+
267
+ puts 'path: ' + path.inspect if @debug
268
+ e = doc.element(path)
269
+ e.delete if e
270
+
264
271
  end
265
272
 
266
273
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindwords
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  aWH7D2AmhOpqNwWnPHzWR/yzpigAVTrvpHfRxZleQj6Z/090nIH2KR0RdioMmPFq
36
36
  3+574KQzs/gR9Y5a+iMcvHRN
37
37
  -----END CERTIFICATE-----
38
- date: 2021-01-20 00:00:00.000000000 Z
38
+ date: 2021-01-25 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: line-tree
@@ -57,6 +57,26 @@ dependencies:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: 0.9.1
60
+ - !ruby/object:Gem::Dependency
61
+ name: rxfhelper
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.1'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.1.3
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.1'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.1.3
60
80
  description:
61
81
  email: digital.robertson@gmail.com
62
82
  executables: []
metadata.gz.sig CHANGED
Binary file