mindwords 0.5.1 → 0.5.6
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 +99 -12
- metadata +2 -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: 9278b3fbcf3da1caed6dd21c274bb8b26e12dec525d05ecf322965b083e8c884
|
4
|
+
data.tar.gz: 8c9b4a404897fd119b64f13e7140daecc8eb55f404595e001508b0b8dd031b7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d4aa5d8a2d6fbc11492518c9be080d98adf122240867baea88d94dfb2b87781bb0e6f94aa5ea7dc632e9be6525c2a3fe02b854b26d86f57accef214b533a904
|
7
|
+
data.tar.gz: 96d3d52f2c88e2419aee86737469a837c51985fc716277cd97694f5f32905ee349e7bbbb40e63e121555cdb81c5b90d5b06baabc28b7a1011a00c98fbb584a35
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mindwords.rb
CHANGED
@@ -20,26 +20,84 @@ class MindWords
|
|
20
20
|
using ColouredText
|
21
21
|
using HashCopy
|
22
22
|
|
23
|
-
attr_accessor :lines
|
23
|
+
attr_accessor :lines, :filepath
|
24
24
|
|
25
|
-
def initialize(raws, parent: nil, debug: false)
|
25
|
+
def initialize(raws='', parent: nil, debug: false)
|
26
26
|
|
27
27
|
@parent, @debug = parent, debug
|
28
|
+
|
29
|
+
s, type = RXFHelper.read raws
|
28
30
|
|
29
|
-
|
31
|
+
@filepath = raws if type == :file or type == :dfs
|
30
32
|
@lines = s.strip.gsub(/^\n/,'').lines
|
31
33
|
@lines.shift if @lines.first =~ /<\?mindwords\?>/
|
32
34
|
|
33
35
|
end
|
34
36
|
|
37
|
+
def add(line)
|
38
|
+
@lines << line
|
39
|
+
end
|
40
|
+
|
41
|
+
def breadcrumb()
|
42
|
+
@parent.attributes[:breadcrumb].split(/ +\/ +/) if @parent
|
43
|
+
end
|
44
|
+
|
45
|
+
|
35
46
|
def element(id)
|
36
47
|
|
37
|
-
doc = Rexle.new(
|
48
|
+
doc = Rexle.new(to_xml())
|
38
49
|
e = doc.root.element("//*[@id='#{id}']")
|
39
50
|
#e.attributes[:breadcrumb].to_s if e
|
40
51
|
|
41
52
|
end
|
53
|
+
|
54
|
+
def hashtags()
|
55
|
+
@parent.attributes[:hashtags].split if @parent
|
56
|
+
end
|
57
|
+
|
58
|
+
def save(file=@filepath)
|
59
|
+
|
60
|
+
return if @lines.empty?
|
61
|
+
|
62
|
+
puts 'before save' if @debug
|
63
|
+
File.write file, to_s()
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
# Accepts a list of words with the aim of returning a MindWords document
|
68
|
+
# using matched words with hashtags from the existing MindWords document.
|
69
|
+
#
|
70
|
+
def reflect(raws)
|
71
|
+
|
72
|
+
h = to_h
|
73
|
+
|
74
|
+
missing_words = []
|
75
|
+
|
76
|
+
# add the tags from the main list
|
77
|
+
a = raws.strip.lines.map do |x|
|
78
|
+
if h[x.chomp] then
|
79
|
+
[x.chomp, h[x.chomp]]
|
80
|
+
else
|
81
|
+
missing_words << x
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
end.compact
|
42
85
|
|
86
|
+
# add any linkage words from the tags
|
87
|
+
#
|
88
|
+
a.map(&:last).flatten(1).each do |s|
|
89
|
+
|
90
|
+
a << [s, h[s]] if h[s]
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
# remove suplicates lines and transform it into a raw mindwords format
|
95
|
+
#
|
96
|
+
raws3 = a.uniq.map {|s,tags| [s, tags.map {|x| '#' + x }.join(' ')].join(' ') }.join("\n")
|
97
|
+
|
98
|
+
[MindWords.new(raws3), missing_words]
|
99
|
+
|
100
|
+
end
|
43
101
|
|
44
102
|
def search(keyword)
|
45
103
|
|
@@ -60,7 +118,11 @@ class MindWords
|
|
60
118
|
|
61
119
|
a2 = a.sort_by(&:last).map(&:first)
|
62
120
|
puts 'a2: ' + a2.inspect if @debug
|
63
|
-
|
121
|
+
e = element(keyword.downcase.gsub(/ +/,'-'))
|
122
|
+
|
123
|
+
return nil if e.nil?
|
124
|
+
|
125
|
+
MindWords.new(a2.join, parent: e, debug: @debug)
|
64
126
|
|
65
127
|
end
|
66
128
|
|
@@ -102,11 +164,20 @@ class MindWords
|
|
102
164
|
@lines = tag_sort().lines
|
103
165
|
self
|
104
166
|
end
|
167
|
+
|
168
|
+
def to_a()
|
169
|
+
|
170
|
+
@lines.map do |x|
|
171
|
+
s, rawtags = x.split(/(?= #)/,2)
|
172
|
+
[s, rawtags.scan(/(?<=#)\w+/)]
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
105
176
|
|
106
177
|
def to_h()
|
107
|
-
|
178
|
+
to_a.to_h
|
108
179
|
end
|
109
|
-
|
180
|
+
|
110
181
|
def to_hashtags()
|
111
182
|
@hashtags
|
112
183
|
end
|
@@ -116,10 +187,12 @@ class MindWords
|
|
116
187
|
sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
|
117
188
|
end
|
118
189
|
|
190
|
+
alias to_tree to_outline
|
191
|
+
|
119
192
|
def to_s(colour: false)
|
120
193
|
|
121
194
|
header = "<?mindwords?>\n\n"
|
122
|
-
return header + @lines.join unless colour
|
195
|
+
return header + @lines.map(&:chomp).join("\n") unless colour
|
123
196
|
|
124
197
|
body = @lines.map do |x|
|
125
198
|
title, hashtags = x.split(/(?=#)/,2)
|
@@ -128,13 +201,27 @@ class MindWords
|
|
128
201
|
|
129
202
|
header + body
|
130
203
|
|
131
|
-
end
|
204
|
+
end
|
132
205
|
|
133
206
|
def to_words()
|
134
|
-
|
135
|
-
|
207
|
+
|
208
|
+
h = {}
|
209
|
+
|
210
|
+
Rexle.new(to_xml).root.each_recursive do |e|
|
211
|
+
|
212
|
+
h[e.attributes[:title]] = {
|
213
|
+
breadcrumb: e.attributes[:breadcrumb],
|
214
|
+
hashtags: e.attributes[:hashtags]
|
215
|
+
}
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
h
|
220
|
+
|
221
|
+
end
|
136
222
|
|
137
223
|
def to_xml()
|
224
|
+
build() unless @xml
|
138
225
|
@xml
|
139
226
|
end
|
140
227
|
|
@@ -198,7 +285,7 @@ class MindWords
|
|
198
285
|
|
199
286
|
|
200
287
|
node = if @parent then
|
201
|
-
found = doc.root.element('//' + @parent)
|
288
|
+
found = doc.root.element('//' + @parent.name)
|
202
289
|
found ? found : doc.root
|
203
290
|
else
|
204
291
|
doc.root
|
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.5.
|
4
|
+
version: 0.5.6
|
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-
|
38
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: line-tree
|
metadata.gz.sig
CHANGED
Binary file
|