pxindex 0.1.4 → 0.1.5
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/pxindex.rb +31 -6
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b34bf0b175a8b4cb95208c4c24b8615a9aed40c
|
4
|
+
data.tar.gz: 3f4549f119fd31fa145dc6650133599ccb98ae08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b12644b4df55c7df9987f4b2cb90ac22e6374b686efbabb0afd28fbaf7b11190c3b2b4a274da0201fe8d421b394cefd8dd0ed805f451bf45a38f75e2f24bf20
|
7
|
+
data.tar.gz: 904d998fd6a740e957582e3d63b9bbf4ec4d42ea8766ff0a0dda15cc0fd159e379274004e5fe79a660d238982d162367c2d862d74993abf982b22a60893bd469
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/pxindex.rb
CHANGED
@@ -7,8 +7,11 @@ require 'polyrex-headings'
|
|
7
7
|
|
8
8
|
class PxIndex
|
9
9
|
|
10
|
-
def initialize(raw_s, debug: false)
|
10
|
+
def initialize(raw_s, debug: false, allsorted: false, indexsorted: false)
|
11
11
|
|
12
|
+
@sorted = allsorted
|
13
|
+
@debug = debug
|
14
|
+
|
12
15
|
s, _ = RXFHelper.read raw_s
|
13
16
|
|
14
17
|
lines = s.lines
|
@@ -19,8 +22,12 @@ class PxIndex
|
|
19
22
|
a = LineTree.new(lines.join.gsub(/^# [a-z]\n/,'')).to_a
|
20
23
|
a2 = a.group_by {|x| x.first[0] }.to_a
|
21
24
|
|
22
|
-
s2 = a2.map
|
23
|
-
|
25
|
+
s2 = a2.map do |x|
|
26
|
+
'# ' + x[0] + "\n\n" + \
|
27
|
+
treeize(allsorted || indexsorted ? sort(x[-1]) : x[-1])
|
28
|
+
end.join("\n\n")
|
29
|
+
|
30
|
+
puts 's2: ' + s2.inspect if @debug
|
24
31
|
@raw_px = header.join + "\n" + s2
|
25
32
|
|
26
33
|
@px = PolyrexHeadings.new(@raw_px).to_polyrex
|
@@ -28,7 +35,7 @@ class PxIndex
|
|
28
35
|
|
29
36
|
@s = ''
|
30
37
|
@a = []
|
31
|
-
|
38
|
+
|
32
39
|
|
33
40
|
end
|
34
41
|
|
@@ -141,11 +148,29 @@ class PxIndex
|
|
141
148
|
|
142
149
|
end
|
143
150
|
|
151
|
+
def sort(a)
|
152
|
+
puts 'sorting ... a: ' + a.inspect if @debug
|
153
|
+
return sort_children(a) if a.first.is_a? String
|
154
|
+
|
155
|
+
r = a.sort_by do |x|
|
156
|
+
next unless x[0].is_a? String
|
157
|
+
x[0]
|
158
|
+
end
|
159
|
+
puts 'after sort: ' + r.inspect if @debug
|
160
|
+
r
|
161
|
+
end
|
162
|
+
|
163
|
+
def sort_children(a)
|
164
|
+
[a[0]] + a[1..-1].sort_by {|x| x[0]}
|
165
|
+
end
|
166
|
+
|
144
167
|
def treeize(obj, indent=-2)
|
145
168
|
|
146
169
|
if obj.is_a? Array then
|
147
|
-
|
148
|
-
obj.map {|x| treeize(x, indent+1)}.join("\n")
|
170
|
+
|
171
|
+
r = (@sorted ? sort(obj) : obj).map {|x| treeize(x, indent+1)}.join("\n")
|
172
|
+
puts 'r: ' + r.inspect if @debug
|
173
|
+
r
|
149
174
|
|
150
175
|
else
|
151
176
|
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|