pxindex 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ef7141d18c5db60d4c2e131b69947b5bf6a2578
4
- data.tar.gz: 6c17a92099097c02ccf69fa4970d194b02c8272c
3
+ metadata.gz: aa8e72a6b88709e91b08b64c3b69a6555d0bde8b
4
+ data.tar.gz: e7f0839043b1ed3db016c13e298bb7c19b3e9c66
5
5
  SHA512:
6
- metadata.gz: 0473b8c93e09b00b6c75d1b3781edef5d5d3b12214e79f1b3f22bf0efe79e69e82b84c1880bd92c83e21fdb729e6f25a2989d350549287c8f798af2f2d284c1e
7
- data.tar.gz: ce0144aa5711d952561badc5deb999789505f6af2a5ac1beb6f59b658605323f9d3e224f3ac02249ff3af1376bda7793580e7f1f5ad7caefe6a36d8b19027519
6
+ metadata.gz: 377ef810ad44ba95317d470f74bef51f3e40cf4b02ae7e6429f2baaa92e549dad20f4efbe30befa1838c0ae640dee92df67e7f93cc86f46d8ca91f96907b8a2c
7
+ data.tar.gz: 9c506a295da08a6e25a029dbec93b00889868204ba39f95931af74820ce97f9fb316796c0f7f68240caf48d55b55194e7a4e19add4006ac7e3dce31ce666f7de
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/pxindex.rb CHANGED
@@ -13,25 +13,24 @@ class PxIndex
13
13
  s, _ = RXFHelper.read raw_s
14
14
 
15
15
  @px = PolyrexHeadings.new(s).to_polyrex
16
- @stack = [@px.records]
16
+ @rs = @px.records
17
17
 
18
18
  @s = ''
19
- @result = nil
20
19
 
21
20
  end
22
21
 
23
22
  def q?(s)
24
23
 
25
- if s.length > @s.length + 1 or s[0..-2] != @s then
24
+ if (s.length - @s.length).abs > 1 or s[0..-2] != @s then
26
25
 
27
- @stack = [@px.records]
26
+ @rs = @px.records
28
27
 
29
28
  s2 = ''
30
29
 
31
30
  a = s.chars.map do |x|
32
31
 
33
32
  s2 += x
34
- found = search_records(s2, @stack)
33
+ found = search_records(s2, @rs)
35
34
 
36
35
  break if not found
37
36
  found
@@ -44,7 +43,7 @@ class PxIndex
44
43
 
45
44
  i = s.length-1
46
45
 
47
- records = search_records(s, @stack)
46
+ records = search_records(s, @rs)
48
47
 
49
48
  @s = s
50
49
 
@@ -57,38 +56,45 @@ class PxIndex
57
56
 
58
57
  private
59
58
 
60
- def search_records(raw_s, stack=@stack)
61
-
62
- return @result if raw_s[-1] == ' '
63
- keywords = raw_s.split(/ /)
59
+ def search_records(raw_s, rs=@rs)
64
60
 
65
- s = if keywords.length > 1 then
61
+
62
+ if raw_s[-1] == ' ' then
66
63
 
67
- r = stack.last.flat_map(&:records)
68
- stack << r if r.any?
69
-
70
- keywords.last
64
+ child_records = rs.flat_map(&:records)
71
65
 
72
- else
73
- raw_s
66
+ if child_records.length > 0 then
67
+ @rs = child_records
68
+ return child_records
69
+ else
70
+ return nil
71
+ end
74
72
  end
73
+
74
+ keywords = raw_s.split(/ /)
75
+
76
+ s = keywords.length > 1 ? keywords.last : raw_s
75
77
 
76
- a = stack.last.select {|x| x.title[0..s.length-1] == s}
78
+ a = rs.select {|x| x.title[0..s.length-1] == s}
77
79
 
78
- if a.any? then
80
+ if s.length == 1 and a.any? and keywords.length < 2 then
81
+ a = a.first.records
82
+ end
83
+
84
+ if a.any? then
79
85
 
80
- stack << a
81
- #@result = a.map(&:title)
82
- @result = a
86
+ @rs = a
83
87
 
84
88
  else
85
89
 
86
- r = stack.last.flat_map(&:records)
90
+ return nil unless keywords.length > 1
91
+
92
+ r = rs.flat_map(&:records)
87
93
 
88
94
  if r.any? then
89
95
 
90
- stack << r
91
- search_records(s, stack)
96
+ @rs = r
97
+ search_records(s, rs)
92
98
 
93
99
  else
94
100
 
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  MrilunBr0ny9pMGbDRKeTfgMh9LinxPgD3BjXqZ78prB3LDxWO8kA/yDt5sLGSiq
32
32
  n8uRSvQvGormuQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-11-30 00:00:00.000000000 Z
34
+ date: 2016-12-01 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: polyrex-headings
metadata.gz.sig CHANGED
Binary file