mindwords 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mindwords.rb +39 -32
- metadata +22 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 318da7a9e4daf9a4f4d69d4315d062fab0f4b2876c3a0302a86d4d1b40909a32
|
4
|
+
data.tar.gz: cd0336cf0a70c0e90fec5964f5a987cbad0abb9e295fc96ddf54a6999832af91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eb530ac7ff6db8b68e2827c51a7ad4ed0ed7244340e842b6ff967c2da1f32a777fff8fc2ddc91d3d04380d0e045cb9d468eba883bf064c8dd00f4686af064e2
|
7
|
+
data.tar.gz: 41708695837cfdc20e091889d88bb1d4e1d8a8c564855f5dbd75f640fc773ffd080353c30f073e4bbb8f76ff5e2ebefccc99a7272d55992358e22f4c8e9984ed
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mindwords.rb
CHANGED
@@ -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(
|
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
|
-
|
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
|
-
|
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(/ +/,'
|
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
|
-
[
|
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[
|
253
|
-
|
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
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
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.
|
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-
|
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
|