pxindex 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/pxindex.rb +80 -80
  4. data.tar.gz.sig +0 -0
  5. metadata +38 -34
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 734c93bfeb579db8039881909574a503747336f34ba3a66ceca7a89441e0b4ca
4
- data.tar.gz: a940f38f6d511ed008328a0b314d9c41915af8e20705a2f167abe5b272a52235
3
+ metadata.gz: 1668eb3de6636f0cf6ee89fd247de311c2a5564c48de17a46049663a7748e2cf
4
+ data.tar.gz: '018283918b471eb3ec25193a1fc5e07b523caedacb5dc633f34ba8974c8f3b13'
5
5
  SHA512:
6
- metadata.gz: d52628ae2564c1757d29fa6f6c258d4baf7941d3350d6539a416636b2caae61b432d8edd067690541f059afb0910ac26fa0e85f65a9477eb2ee341181db74534
7
- data.tar.gz: e9b3486ce29f3961e547f656f242cd96dbd1ba63061d92595e88c830b8c2d895092bd57734c678eb266de802330176abc2968d20bc16fdff240d4b8105d5d037
6
+ metadata.gz: 646bed272d796dc7fbcde32f82b7326ff896bea9bbeb095befe83d71bdad634ef953534072aa26c1f30078f43dfd6fb4c025288206ed5f6d20076838626c03fa
7
+ data.tar.gz: 26666a0d64048cbbf39616581a009ade96f9101d197398bf2f5cded6c14aee8aa3f3a09860aaf81b40d98070a2d0a915feb204edefb0a88035cdf11e41d13c0d
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/pxindex.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  require 'nokogiri'
6
6
  require 'pxindex-builder'
7
7
  require 'polyrex-headings'
8
-
8
+ require 'rxfreader'
9
9
 
10
10
 
11
11
  class PxIndex
@@ -13,8 +13,8 @@ class PxIndex
13
13
  def initialize(raw_s=nil, debug: false, allsorted: false, indexsorted: false)
14
14
 
15
15
  @allsorted, @indexsorted = allsorted, indexsorted
16
- @debug = debug
17
-
16
+ @debug = debug
17
+
18
18
  read raw_s if raw_s
19
19
 
20
20
  end
@@ -22,140 +22,140 @@ class PxIndex
22
22
  # Returns a PxIndexBuilder object which can build from am index or phrases
23
23
  #
24
24
  def import(s)
25
-
25
+
26
26
  read(PxIndexBuilder.new(s, debug: @debug).to_s)
27
-
27
+
28
28
  end
29
-
29
+
30
30
  def parent()
31
31
  @rs.first
32
32
  end
33
33
 
34
34
  def q?(s)
35
-
35
+
36
36
  return @a.last if s == @s
37
37
  puts '@s : ' + @s.inspect if @debug
38
38
  puts 's: ' + s.inspect if @debug
39
-
40
- # @s is used to store the previous string input to compare it with
39
+
40
+ # @s is used to store the previous string input to compare it with
41
41
  # the new string input
42
-
42
+
43
43
  if (s.length - @s.length).abs >= 1 or s[0..-2] != @s then
44
-
45
- @s = s
44
+
45
+ @s = s
46
46
 
47
47
  @rs = @px.records.flat_map(&:records)
48
-
48
+
49
49
  s2 = ''
50
-
50
+
51
51
  @a = s.chars.map do |x|
52
52
 
53
53
  s2 += x
54
54
  found = search_records(s2, @rs)
55
-
55
+
56
56
  break if not found
57
57
  found
58
-
58
+
59
59
  end
60
60
 
61
61
  return @a ? @a.last : nil
62
-
62
+
63
63
  end
64
-
64
+
65
65
  return []
66
-
66
+
67
67
  end
68
68
 
69
69
  alias query q?
70
-
70
+
71
71
  def build_html()
72
-
72
+
73
73
  @px.each_recursive do |x, parent|
74
-
74
+
75
75
  if x.is_a? Entry then
76
-
76
+
77
77
  trail = parent.attributes[:trail]
78
78
  s = x.title.gsub(/ +/,'-')
79
79
  x.attributes[:trail] = trail.nil? ? s : trail + '/' + s
80
-
80
+
81
81
  end
82
-
82
+
83
83
  end
84
84
 
85
85
  doc = Nokogiri::XML(@px.to_xml)
86
86
  xsl = Nokogiri::XSLT(xslt())
87
87
 
88
88
  html_doc = Rexle.new(xsl.transform(doc).to_s)
89
-
90
- html_doc.root.css('.atopic').each do |e|
91
-
89
+
90
+ html_doc.root.css('.atopic').each do |e|
91
+
92
92
  puts 'e: ' + e.parent.parent.xml.inspect if @debug
93
-
93
+
94
94
  href = e.attributes[:href]
95
95
  if href.empty? or href[0] == '!' then
96
-
96
+
97
97
  if block_given? then
98
-
98
+
99
99
  yield(e)
100
-
100
+
101
101
  else
102
-
102
+
103
103
  e.attributes[:href] = '#' + e.attributes[:trail].split('/')\
104
104
  .last.downcase
105
-
105
+
106
106
  end
107
107
  end
108
108
  end
109
-
109
+
110
110
  html_doc.xml(pretty: true, declaration: false)
111
-
111
+
112
112
  end
113
-
113
+
114
114
  def to_px()
115
115
  @px
116
116
  end
117
-
117
+
118
118
  def to_s()
119
119
  @raw_px
120
120
  end
121
121
 
122
122
  private
123
-
123
+
124
124
  def read(raw_s)
125
-
126
- s, _ = RXFHelper.read raw_s
127
-
125
+
126
+ s, _ = RXFReader.read raw_s
127
+
128
128
  lines = s.lines
129
129
 
130
130
  header = []
131
131
  header << lines.shift until lines[0].strip.empty?
132
-
132
+
133
133
  a = LineTree.new(lines.join.gsub(/^# [a-z]\n/,'')).to_a
134
134
  a2 = a.group_by {|x| x.first[0] }.sort.to_a
135
-
136
- s2 = a2.map do |x|
135
+
136
+ s2 = a2.map do |x|
137
137
  '# ' + x[0] + "\n\n" + \
138
138
  treeize(@allsorted || @indexsorted ? sort(x[-1]) : x[-1])
139
139
  end.join("\n\n")
140
-
140
+
141
141
  puts 's2: ' + s2.inspect if @debug
142
142
  @raw_px = header.join + "\n" + s2
143
143
 
144
- @px = PolyrexHeadings.new(@raw_px).to_polyrex
144
+ @px = PolyrexHeadings.new(@raw_px).to_polyrex
145
145
  @rs = @px.records.flat_map()
146
146
 
147
147
  @s = ''
148
- @a = []
148
+ @a = []
149
149
  end
150
150
 
151
151
  def search_records(raw_s, rs=@rs)
152
-
152
+
153
153
  puts 'raw_s : ' + raw_s.inspect if @debug
154
-
154
+
155
155
  if raw_s[-1] == ' ' then
156
156
 
157
157
  child_records = rs.flat_map(&:records)
158
-
158
+
159
159
  if child_records.length > 0 then
160
160
  @rs = child_records
161
161
  return child_records
@@ -165,67 +165,67 @@ class PxIndex
165
165
  end
166
166
 
167
167
  keywords = raw_s.split(/ /)
168
-
168
+
169
169
  s = keywords.length > 1 ? keywords.last : raw_s
170
-
171
- a = rs.select {|x| x.title[0..s.length-1] == s}
172
-
170
+
171
+ a = rs.select {|x| x.title[0..s.length-1] == s}
172
+
173
173
  if @debug then
174
- puts 'a: ' + a.inspect
174
+ puts 'a: ' + a.inspect
175
175
  if a.any? then
176
176
  puts 'a.map ' + a.map(&:title).inspect
177
177
  end
178
- end
179
-
178
+ end
179
+
180
180
  if a.any? then
181
-
181
+
182
182
  @rs = a
183
-
183
+
184
184
  else
185
185
 
186
186
  return nil unless keywords.length > 1
187
-
187
+
188
188
  r = rs
189
189
 
190
190
  if r.any? then
191
-
192
- @rs = r
191
+
192
+ @rs = r
193
193
  search_records(s, rs)
194
-
194
+
195
195
  else
196
-
196
+
197
197
  return nil
198
-
198
+
199
199
  end
200
-
200
+
201
201
  end
202
202
 
203
203
  end
204
-
204
+
205
205
  def sort(a)
206
-
206
+
207
207
  puts 'sorting ... a: ' + a.inspect if @debug
208
208
  return sort_children(a) if a.first.is_a? String
209
-
210
- r = a.sort_by do |x|
209
+
210
+ r = a.sort_by do |x|
211
211
  next unless x[0].is_a? String
212
212
  x[0]
213
213
  end
214
-
214
+
215
215
  puts 'after sort: ' + r.inspect if @debug
216
-
216
+
217
217
  r
218
-
218
+
219
219
  end
220
-
220
+
221
221
  def sort_children(a)
222
222
  [a[0]] + a[1..-1].sort_by {|x| x[0]}
223
223
  end
224
-
224
+
225
225
  def treeize(obj, indent=-2)
226
226
 
227
227
  if obj.is_a? Array then
228
-
228
+
229
229
  r = (@allsorted ? sort(obj) : obj).map {|x| treeize(x, indent+1)}.join("\n")
230
230
  puts 'r: ' + r.inspect if @debug
231
231
  r
@@ -237,7 +237,7 @@ class PxIndex
237
237
  end
238
238
  end
239
239
 
240
-
240
+
241
241
  def xslt()
242
242
  <<EOF
243
243
  <?xml version="1.0" encoding="UTF-8"?>
@@ -283,8 +283,8 @@ class PxIndex
283
283
  </xsl:template>
284
284
 
285
285
 
286
- </xsl:stylesheet>
286
+ </xsl:stylesheet>
287
287
  EOF
288
- end
288
+ end
289
289
 
290
290
  end
data.tar.gz.sig CHANGED
Binary file
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.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,27 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgwMzE0MjEwMzUxWhcN
15
- MTkwMzE0MjEwMzUxWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCjAGJU
17
- TtLHBA8kLkGItpBBYflhiLbF0zNnLqg+DWs/73aI1hZLkFVoQA5/Mjq4YnC/4NPY
18
- g8ZXddJ6v9kitiDByucN/6oZnS91CGmS1umm2IRorXVl48cMzx/GO96f7uh8pf7l
19
- 5VR2Rzb0hJyXu0f9GYdaBe1jVbNdupYSHFdpxW3QRPK+QUiz/0l3qlcmruDmpCsI
20
- hqbFQ8OJS3SLhs3uEl2hqQvS8ijZQaGzOT9vnQVYRELBzBTv42YLyc28E7yRbGfK
21
- uevJOPVG/XUEcmp6TuVvc46ZWXb/nyyPodjkEavZibUi2hB7+uMDuA0w/R8A5CHG
22
- MubZkWqInhFzGfupAgMBAAGjgYowgYcwCQYDVR0TBAIwADALBgNVH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AUTU1yY/yIYUC3PRK4iCVNABYrrx1/knM5
36
+ P80D+02gWIUT41dw6mBHO32N
32
37
  -----END CERTIFICATE-----
33
- date: 2019-01-17 00:00:00.000000000 Z
38
+ date: 2022-02-23 00:00:00.000000000 Z
34
39
  dependencies:
35
40
  - !ruby/object:Gem::Dependency
36
41
  name: nokogiri
@@ -38,20 +43,20 @@ dependencies:
38
43
  requirements:
39
44
  - - "~>"
40
45
  - !ruby/object:Gem::Version
41
- version: '1.10'
46
+ version: '1.13'
42
47
  - - ">="
43
48
  - !ruby/object:Gem::Version
44
- version: 1.10.1s
49
+ version: 1.13.3
45
50
  type: :runtime
46
51
  prerelease: false
47
52
  version_requirements: !ruby/object:Gem::Requirement
48
53
  requirements:
49
54
  - - "~>"
50
55
  - !ruby/object:Gem::Version
51
- version: '1.10'
56
+ version: '1.13'
52
57
  - - ">="
53
58
  - !ruby/object:Gem::Version
54
- version: 1.10.1s
59
+ version: 1.13.3
55
60
  - !ruby/object:Gem::Dependency
56
61
  name: pxindex-builder
57
62
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +66,7 @@ dependencies:
61
66
  version: '0.2'
62
67
  - - ">="
63
68
  - !ruby/object:Gem::Version
64
- version: 0.2.0
69
+ version: 0.2.1
65
70
  type: :runtime
66
71
  prerelease: false
67
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -71,29 +76,29 @@ dependencies:
71
76
  version: '0.2'
72
77
  - - ">="
73
78
  - !ruby/object:Gem::Version
74
- version: 0.2.0
79
+ version: 0.2.1
75
80
  - !ruby/object:Gem::Dependency
76
81
  name: polyrex-headings
77
82
  requirement: !ruby/object:Gem::Requirement
78
83
  requirements:
79
84
  - - "~>"
80
85
  - !ruby/object:Gem::Version
81
- version: '0.1'
86
+ version: '0.3'
82
87
  - - ">="
83
88
  - !ruby/object:Gem::Version
84
- version: 0.1.9
89
+ version: 0.3.0
85
90
  type: :runtime
86
91
  prerelease: false
87
92
  version_requirements: !ruby/object:Gem::Requirement
88
93
  requirements:
89
94
  - - "~>"
90
95
  - !ruby/object:Gem::Version
91
- version: '0.1'
96
+ version: '0.3'
92
97
  - - ">="
93
98
  - !ruby/object:Gem::Version
94
- version: 0.1.9
99
+ version: 0.3.0
95
100
  description:
96
- email: james@jamesrobertson.eu
101
+ email: digital.robertson@gmail.com
97
102
  executables: []
98
103
  extensions: []
99
104
  extra_rdoc_files: []
@@ -118,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
123
  - !ruby/object:Gem::Version
119
124
  version: '0'
120
125
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.7.6
126
+ rubygems_version: 3.2.22
123
127
  signing_key:
124
128
  specification_version: 4
125
129
  summary: Experimental gem to facilitate a keyword search, by querying a Polyrex document
metadata.gz.sig CHANGED
Binary file