mindwords 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 444a04256394031a941df39803aa0026c9c8e4de2ab9fe4796b363b2ba4c5fe8
4
- data.tar.gz: 69a11f118b88b738bf489cb5530f359ccb1715ea8c025af7e2a7fec2cc4910a2
3
+ metadata.gz: 2cff4e2c8dbff0eee0e0e4fa8fe0411d84d772e4348aca0eef1585e64887a4c2
4
+ data.tar.gz: 434d7757907e356ce733a1ab1f81a185677bd580ac9bb56c288b821adac2508c
5
5
  SHA512:
6
- metadata.gz: f3fc50a6df2a8c9912a4177174db97e3d36e21c2d5d3ab1389165adb93f9254cfac557953c6229b1de35ff61847463b2bd24539c8e72a0dcd85af02cfaca2e10
7
- data.tar.gz: 692a05e1afd552b7e7efc8dd8ef03926d073d16dfaae6f20bcc190dfa1ca931070d78c6d5b1a134648d196edbac16fcac0206f17f554279bd320a9349dbe992e
6
+ metadata.gz: 2443f5089c5b27b799a0c9d9c059a8157817f16bc82ffe2e868c60fa3b55c1fdf27778e8a064b4d48e8a8bf671845010ab3ab08d5481d924626f38b2861ba369
7
+ data.tar.gz: daac6e6f0b0a4be3dbd664eb9c1e2e489b29b1435b4ec0e507fd35f4224d51d7b79073d2ca21e5ed836a1c7fd4886ef28b2883cf515bf9789bedbb7c171dcdfb
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -5,13 +5,26 @@
5
5
  require 'rexle'
6
6
  require 'line-tree'
7
7
 
8
+ module HashCopy
9
+ refine Hash do
10
+
11
+ def deep_clone()
12
+ Marshal.load(Marshal.dump(self))
13
+ end
14
+
15
+ end
16
+ end
17
+
8
18
  class MindWords
9
19
  using ColouredText
20
+ using HashCopy
21
+
10
22
 
11
23
  def initialize(s, parent: nil, debug: false)
12
24
 
13
25
  @debug = debug
14
- @a = s.strip.lines
26
+ @a = s.strip.gsub(/^\n/,'').lines
27
+ @a.shift if @a.first =~ /<\?mindwords\?>/
15
28
 
16
29
  lines = @a.map do |line|
17
30
 
@@ -20,18 +33,21 @@ class MindWords
20
33
  end
21
34
 
22
35
  h = {}
36
+ @hashtags = {}
23
37
 
24
- lines.each do |x|
38
+ lines.each do |title, rawtags|
25
39
 
26
- x.last.scan(/#(\w+)/).flatten(1).each do |rawtag|
40
+ rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
27
41
  tag = rawtag.gsub(/ +/, '_')
28
42
  h[tag] ||= []
29
- h[tag] << x.first
43
+ h[tag] << title
30
44
  end
31
45
 
32
46
  end
47
+
48
+ @hashtags = h.deep_clone.sort.map {|tag, fields| [tag, fields.sort]}.to_h
33
49
 
34
- # does the key exist as a field?
50
+ # does the key exist as a field? Nesting of hash object is performed here.
35
51
 
36
52
  h.keys.each do |key|
37
53
 
@@ -76,11 +92,33 @@ class MindWords
76
92
  doc.root
77
93
  end
78
94
 
79
- @xml = node.xml pretty: true
80
95
  @outline = treeize node
81
96
 
97
+ node.root.each_recursive do |e|
98
+
99
+ s = e.parent.attributes[:breadcrumb] ? \
100
+ e.parent.attributes[:breadcrumb].to_s + ' / ' : ''
101
+ e.attributes[:breadcrumb] = s + e.value.strip
102
+
103
+ r = @a.grep(/^#{e.attributes[:title]} #/i)
104
+ next unless r.any?
105
+ e.attributes[:hashtags] = r[0].scan(/(?<=#)\w+/).join(' ')
106
+ e.attributes[:id] = e.attributes[:title].downcase.gsub(/ +/,'-')
107
+
108
+ end
109
+
110
+ @xml = node.xml pretty: true
111
+
82
112
  end
83
113
 
114
+ def element(id)
115
+
116
+ doc = Rexle.new(@xml)
117
+ e = doc.root.element("//*[@id='#{id}']")
118
+ #e.attributes[:breadcrumb].to_s if e
119
+
120
+ end
121
+
84
122
  def search(keyword)
85
123
 
86
124
  a = @a.grep(/#{keyword}/i).map do |line|
@@ -146,6 +184,10 @@ class MindWords
146
184
  def to_h()
147
185
  @h
148
186
  end
187
+
188
+ def to_hashtags()
189
+ @hashtags
190
+ end
149
191
 
150
192
  def to_outline(sort: true)
151
193
  sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
@@ -153,12 +195,16 @@ class MindWords
153
195
 
154
196
  def to_s(colour: false)
155
197
 
156
- return @a.join unless colour
198
+ header = "<?mindwords?>\n\n"
199
+ return header + @a.join unless colour
157
200
 
158
- @a.map do |x|
201
+ body = @a.map do |x|
159
202
  title, hashtags = x.split(/(?=#)/,2)
160
203
  title + hashtags.chomp.brown
161
204
  end.join("\n")
205
+
206
+ header + body
207
+
162
208
  end
163
209
 
164
210
  def to_words()
@@ -179,11 +225,16 @@ class MindWords
179
225
 
180
226
  case x
181
227
  when String
182
- [x.gsub(/ +/,'_'), {}, x]
228
+ [x.gsub(/ +/,'_'), {title: x}, x]
183
229
  when Hash
184
- [x.keys.first, {}, x.keys.first.gsub(/_/,' '), *rexlize(x.values.first)]
230
+ [
231
+ x.keys.first.gsub(/_/,' '),
232
+ {title: x.keys.first},
233
+ x.keys.first,
234
+ *rexlize(x.values.first)
235
+ ]
185
236
  when Array
186
- [x.first, {}, x.first.gsub(/_/,' '), *rexlize(x.last)]
237
+ [x.first.gsub(/_/,' '), {title: x.first}, x.first, *rexlize(x.last)]
187
238
  end
188
239
  end
189
240
 
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.2.0
4
+ version: 0.3.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-18 00:00:00.000000000 Z
38
+ date: 2021-01-20 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: line-tree
metadata.gz.sig CHANGED
@@ -1 +1,3 @@
1
- )��7��Pl#��p��H��}��������!K�1N��3��F��v�R���:��he}-�h}���'TE�@���)m1���XR_e�W��d��;��9�ע�̄�k���)�Ez��1`v*���-50�8*l�����_��[$��%˯�v\���b���M�����d̉�B���djG���4�~��ҁHC���g*�7oW��H�ʠ�E�⻆ո���WPw��J�q��9�Ǔ�̥l[�H�v�k�.!�/Yp�#w6 �mbDƒ�t�(�~���KX�[��t�8�k���h�E��!�/��6=�52��>�I ,��G�����z�G"<����+�ũ����i�������ͣА,�o�W�섚h%�n�
1
+ Q
2
+ R,����� �7[
3
+ @A���X�#Y[�zHC�[�O�Q��'�¹������V�d%�˶�9o�F�'$\��t��(*��`D��fT�]΢�M���A1</��j�&�@uŸ{8H ��0�F����4&�?��fv�;�b�'W+����|�B$i�Y�[��[�����F�R��$K@�\�p0�k����܉/�:r6�"c��0�3ϓq��B��}ؐ@$�V!8�SK"/lBʀD�����M�+�X��>����