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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 371f60b99e6c9076ba7ba40b9babee5fb14de322
4
- data.tar.gz: c49e053bbf77f5fc898d2c3091b034c8e7804f48
3
+ metadata.gz: 0b34bf0b175a8b4cb95208c4c24b8615a9aed40c
4
+ data.tar.gz: 3f4549f119fd31fa145dc6650133599ccb98ae08
5
5
  SHA512:
6
- metadata.gz: 127ff27b3a45a9dc8b45628d980c632bdc9e80ce40ab1944fcdacfef06031720dd95db190de82a7298f4d60c20b5955ecfd1cf56fdf5966fc5d4931cc7a5c241
7
- data.tar.gz: 660e95f01e0750bab4e4830b2f6511f00fd4cecd7339a266778be0526b2823a9bf22222c4b5f65df26f34c21823a5a957a04da55d8763dfda3f201209abcfba5
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 {|x| '# ' + x[0] + "\n\n" + treeize(x[-1]) }.join("\n\n")
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
- @debug = debug
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pxindex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file