pxindex 0.1.6 → 0.2.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
  SHA1:
3
- metadata.gz: 18376538812d5683a94b7c731aa1ddb65b1a43ab
4
- data.tar.gz: 1ca021e792789d8392ce19d933796c3f4abc4903
3
+ metadata.gz: 7180ae0be92aec1948a8592f67fd96c6138ac5a3
4
+ data.tar.gz: 040f39f96f57dd9554bd16292f21ea22a1a551db
5
5
  SHA512:
6
- metadata.gz: 4333b7f85887ae277f49a422b5f9a482440c8d966fe7db59f23d908e39a6c8cf1904a0268be88a097694cffec28d427421bb6bc8d95283e8c0cf99ed04ea9850
7
- data.tar.gz: bd597f64135de19380d0020c23b28e8036bc46187d8dcf088f145001644876bd5bbc3f7982635dc623788beef7045fa56f7a11fd1a135e82ac8dcfdaa489071b
6
+ metadata.gz: 91b355f5c224817cada42a6ae93d57c7287cbddb1a1d04d5f5e1e16c9741a13f82c84626f499030bc6fb1864c5481ade05e78aa34b76aa1888d0d7507b8daa54
7
+ data.tar.gz: 682442727286c7e103d833345ad3916f7b29ec07aeacac41c665a2e6fdd19666ef791c2d97541cc6a7b754c6abbc6c685b3647bfae39e6fc4feabf1dc6fe16e1
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,41 +2,28 @@
2
2
 
3
3
  # file: pxindex.rb
4
4
 
5
+ require 'pxindex-builder'
5
6
  require 'polyrex-headings'
6
7
 
7
8
 
9
+
8
10
  class PxIndex
9
11
 
10
- def initialize(raw_s, debug: false, allsorted: false, indexsorted: false)
12
+ def initialize(raw_s=nil, debug: false, allsorted: false, indexsorted: false)
11
13
 
12
- @sorted = allsorted
14
+ @allsorted, @indexsorted = allsorted, indexsorted
13
15
  @debug = debug
14
16
 
15
- s, _ = RXFHelper.read raw_s
16
-
17
- lines = s.lines
17
+ read raw_s if raw_s
18
18
 
19
- header = []
20
- header << lines.shift until lines[0].strip.empty?
19
+ end
20
+
21
+ # Returns a PxIndexBuilder object which can build from am index or phrases
22
+ #
23
+ def import(s)
21
24
 
22
- a = LineTree.new(lines.join.gsub(/^# [a-z]\n/,'')).to_a
23
- a2 = a.group_by {|x| x.first[0] }.sort.to_a
25
+ read(PxIndexBuilder.new(s, debug: @debug).to_s)
24
26
 
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
31
- @raw_px = header.join + "\n" + s2
32
-
33
- @px = PolyrexHeadings.new(@raw_px).to_polyrex
34
- @rs = @px.records
35
-
36
- @s = ''
37
- @a = []
38
-
39
-
40
27
  end
41
28
 
42
29
  def parent()
@@ -56,7 +43,7 @@ class PxIndex
56
43
 
57
44
  @s = s
58
45
 
59
- @rs = @px.records
46
+ @rs = @px.records.flat_map(&:records)
60
47
 
61
48
  s2 = ''
62
49
 
@@ -89,6 +76,33 @@ class PxIndex
89
76
  end
90
77
 
91
78
  private
79
+
80
+ def read(raw_s)
81
+
82
+ s, _ = RXFHelper.read raw_s
83
+
84
+ lines = s.lines
85
+
86
+ header = []
87
+ header << lines.shift until lines[0].strip.empty?
88
+
89
+ a = LineTree.new(lines.join.gsub(/^# [a-z]\n/,'')).to_a
90
+ a2 = a.group_by {|x| x.first[0] }.sort.to_a
91
+
92
+ s2 = a2.map do |x|
93
+ '# ' + x[0] + "\n\n" + \
94
+ treeize(@allsorted || @indexsorted ? sort(x[-1]) : x[-1])
95
+ end.join("\n\n")
96
+
97
+ puts 's2: ' + s2.inspect if @debug
98
+ @raw_px = header.join + "\n" + s2
99
+
100
+ @px = PolyrexHeadings.new(@raw_px).to_polyrex
101
+ @rs = @px.records.flat_map()
102
+
103
+ @s = ''
104
+ @a = []
105
+ end
92
106
 
93
107
  def search_records(raw_s, rs=@rs)
94
108
 
@@ -120,7 +134,7 @@ class PxIndex
120
134
  end
121
135
 
122
136
  if s.length == 1 and a.any? and keywords.length < 2 then
123
- a = a.first.records
137
+ #a = a.first.records
124
138
  end
125
139
 
126
140
  if a.any? then
@@ -131,7 +145,7 @@ class PxIndex
131
145
 
132
146
  return nil unless keywords.length > 1
133
147
 
134
- r = rs.flat_map(&:records)
148
+ r = rs #.flat_map(&:records)
135
149
 
136
150
  if r.any? then
137
151
 
@@ -168,7 +182,7 @@ class PxIndex
168
182
 
169
183
  if obj.is_a? Array then
170
184
 
171
- r = (@sorted ? sort(obj) : obj).map {|x| treeize(x, indent+1)}.join("\n")
185
+ r = (@allsorted ? sort(obj) : obj).map {|x| treeize(x, indent+1)}.join("\n")
172
186
  puts 'r: ' + r.inspect if @debug
173
187
  r
174
188
 
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.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -30,8 +30,28 @@ cert_chain:
30
30
  IIkRAfg3vUhmtNQu26Gsi9aZcJAGPKIjdRuYc9oyiGpJv0cQ02HBGRUXnoKS7XYT
31
31
  QDc=
32
32
  -----END CERTIFICATE-----
33
- date: 2018-03-16 00:00:00.000000000 Z
33
+ date: 2018-04-14 00:00:00.000000000 Z
34
34
  dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: pxindex-builder
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.2'
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.2.0
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '0.2'
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
35
55
  - !ruby/object:Gem::Dependency
36
56
  name: polyrex-headings
37
57
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file