mindwords 0.1.1 → 0.1.2

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: 7e0812d6fb0ec5d2b09105de96160ed832007144ac15f036418e1e9207234b60
4
- data.tar.gz: 1c121aae9d22bc87535fb0c8df0c41333530dfa180970bd9685488b49b209f9e
3
+ metadata.gz: 979c08954b01240d160226705d4d6fd2735bda65542d137766f8448154168d96
4
+ data.tar.gz: 38b5068bc8094f08b9225ab5b370274ef80abad45b5acbd1c73ac0dac774b605
5
5
  SHA512:
6
- metadata.gz: 706128a061c541504d6214d0a0cd1bdf23aecb3794761c43d842c9cd24b34d704ae7c1fa70b9ddba67cb8a785b88a72e37f462fe4f6eb5f5c9bfb38c81471f57
7
- data.tar.gz: ad5dce9ac225ba26711d6ab92c16d7fe7a2dcf906173ea52318fe7452437da685227340d3cdaf8061842f3ab5704cf7494a47f5fea9ec122f09cac930b3cd0a7
6
+ metadata.gz: 53bec0cce041880c0daa73fab6a82afa58902f48eabcfef80e7f43d150bd45fb6cae895945f50b90b24532f2acdc6be3962775295ed8446d34b27550ce25f5c5
7
+ data.tar.gz: 1c92d7835762bf2b9f2e25fd7d52dc8d159963ad7a950cf3c6f6eb45fc426ba5cde51fa54950335503efe1cf094855b59c2cc0917412b1f176a8951d2cad5feb
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -5,12 +5,14 @@
5
5
  require 'rexle'
6
6
 
7
7
  class MindWords
8
-
8
+ using ColouredText
9
+
9
10
  def initialize(s, debug: false)
10
11
 
11
12
  @debug = debug
12
-
13
- lines = s.strip.lines.map do |line|
13
+ @a = s.strip.lines
14
+
15
+ lines = @a.map do |line|
14
16
 
15
17
  word = line.split(/ (?=#)/,2)
16
18
 
@@ -41,6 +43,8 @@ class MindWords
41
43
 
42
44
  end
43
45
 
46
+ @h = h
47
+
44
48
  a = rexlize(h)
45
49
  doc = Rexle.new(['root', {}, '', *a])
46
50
 
@@ -64,12 +68,90 @@ class MindWords
64
68
  redundants.compact.each {|x| doc.element(x).delete }
65
69
  rm_duplicates(doc)
66
70
 
71
+ @xml = doc.root.xml pretty: true
67
72
  @outline = treeize doc.root
68
73
 
69
74
  end
75
+
76
+ def search(keyword)
77
+
78
+ a = @a.grep(/#{keyword}/i).map do |line|
79
+
80
+ words = line.split
81
+ r = words.grep /#{keyword}/i
82
+ i = words.index r[0]
83
+
84
+ [line, i]
85
+
86
+ end
87
+
88
+ return nil if a.empty?
89
+ #return a[0][0] if a.length < 2
90
+
91
+ a2 = a.sort_by(&:last).map(&:first)
92
+ MindWords.new(a2.join)
93
+
94
+ end
95
+
96
+ def sort()
97
+ s = @a.sort.join
98
+
99
+ def s.to_s()
100
+ self.lines.map do |x|
101
+ title, hashtags = x.split(/(?=#)/,2)
102
+ title + hashtags.chomp.brown
103
+ end.join("\n")
104
+ end
105
+
106
+ return s
107
+ end
108
+
109
+ def sort!()
110
+ @a = sort().lines
111
+ self
112
+ end
113
+
114
+ def tag_sort()
115
+
116
+ h = @a.group_by {|x| x[/#\w+/]}
117
+ s = h.sort.map {|key, value| value.sort }.join
118
+
119
+ def s.to_s()
120
+ self.lines.map do |x|
121
+ title, hashtags = x.split(/(?=#)/,2)
122
+ title + hashtags.chomp.brown
123
+ end.join("\n")
124
+ end
125
+
126
+ return s
127
+
128
+ end
129
+
130
+ def tag_sort!()
131
+ @a = tag_sort().lines
132
+ self
133
+ end
134
+
135
+ def to_h()
136
+ @h
137
+ end
70
138
 
71
- def to_outline()
72
- @outline
139
+ def to_outline(sort: true)
140
+ sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
141
+ end
142
+
143
+ def to_s(colour: false)
144
+
145
+ return @a.join unless colour
146
+
147
+ @a.map do |x|
148
+ title, hashtags = x.split(/(?=#)/,2)
149
+ title + hashtags.chomp.brown
150
+ end.join("\n")
151
+ end
152
+
153
+ def to_xml()
154
+ @xml
73
155
  end
74
156
 
75
157
  private
@@ -130,6 +212,26 @@ class MindWords
130
212
 
131
213
  lines.join
132
214
  end
215
+
216
+ def tree_sort(a)
217
+
218
+ if a.first.is_a? Array then
219
+ a.sort_by(&:first).map {|x| tree_sort(x) }
220
+ elsif a.any?
221
+ [a.first] + tree_sort(a[1..-1])
222
+ else
223
+ []
224
+ end
225
+ end
133
226
 
134
- end
227
+ def a2tree(a, indent=0)
228
+
229
+ a.map do |row|
230
+ title, *remaining = row
231
+ children = remaining ? a2tree(remaining, indent+1) : ''
232
+ (' ' * indent) + title + "\n" + children
233
+ end.join
135
234
 
235
+ end
236
+
237
+ 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.1.1
4
+ version: 0.1.2
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-06 00:00:00.000000000 Z
38
+ date: 2021-01-10 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
@@ -83,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubyforge_project:
87
- rubygems_version: 2.7.10
86
+ rubygems_version: 3.0.3
88
87
  signing_key:
89
88
  specification_version: 4
90
89
  summary: Helps get what's in your mind into a structure using words and hashtags.
metadata.gz.sig CHANGED
Binary file