pxindex 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ef7141d18c5db60d4c2e131b69947b5bf6a2578
4
+ data.tar.gz: 6c17a92099097c02ccf69fa4970d194b02c8272c
5
+ SHA512:
6
+ metadata.gz: 0473b8c93e09b00b6c75d1b3781edef5d5d3b12214e79f1b3f22bf0efe79e69e82b84c1880bd92c83e21fdb729e6f25a2989d350549287c8f798af2f2d284c1e
7
+ data.tar.gz: ce0144aa5711d952561badc5deb999789505f6af2a5ac1beb6f59b658605323f9d3e224f3ac02249ff3af1376bda7793580e7f1f5ad7caefe6a36d8b19027519
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/lib/pxindex.rb ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: pxindex.rb
4
+
5
+ require 'polyrex-headings'
6
+
7
+
8
+ class PxIndex
9
+
10
+
11
+ def initialize(raw_s)
12
+
13
+ s, _ = RXFHelper.read raw_s
14
+
15
+ @px = PolyrexHeadings.new(s).to_polyrex
16
+ @stack = [@px.records]
17
+
18
+ @s = ''
19
+ @result = nil
20
+
21
+ end
22
+
23
+ def q?(s)
24
+
25
+ if s.length > @s.length + 1 or s[0..-2] != @s then
26
+
27
+ @stack = [@px.records]
28
+
29
+ s2 = ''
30
+
31
+ a = s.chars.map do |x|
32
+
33
+ s2 += x
34
+ found = search_records(s2, @stack)
35
+
36
+ break if not found
37
+ found
38
+
39
+ end
40
+
41
+ return a ? a.last : nil
42
+
43
+ end
44
+
45
+ i = s.length-1
46
+
47
+ records = search_records(s, @stack)
48
+
49
+ @s = s
50
+
51
+ return records
52
+
53
+ end
54
+
55
+ alias query q?
56
+
57
+
58
+ private
59
+
60
+ def search_records(raw_s, stack=@stack)
61
+
62
+ return @result if raw_s[-1] == ' '
63
+ keywords = raw_s.split(/ /)
64
+
65
+ s = if keywords.length > 1 then
66
+
67
+ r = stack.last.flat_map(&:records)
68
+ stack << r if r.any?
69
+
70
+ keywords.last
71
+
72
+ else
73
+ raw_s
74
+ end
75
+
76
+ a = stack.last.select {|x| x.title[0..s.length-1] == s}
77
+
78
+ if a.any? then
79
+
80
+ stack << a
81
+ #@result = a.map(&:title)
82
+ @result = a
83
+
84
+ else
85
+
86
+ r = stack.last.flat_map(&:records)
87
+
88
+ if r.any? then
89
+
90
+ stack << r
91
+ search_records(s, stack)
92
+
93
+ else
94
+
95
+ return nil
96
+
97
+ end
98
+
99
+ end
100
+
101
+ end
102
+
103
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pxindex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE2MTEzMDE4NDAwMVoXDTE3MTEzMDE4NDAwMVowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAK9kL3R7SdZ5roqi7hVC2E2SBcQkAstj1JWbXY2Kk+6lf56cJTP8FNO+G1Am
19
+ TpnKxOLqbmS7vmyUR2MJ6ETHYz0xhzQOBCNNxJ1B8thlI0zz3k+bzpozevFkn5Vr
20
+ 6256vXUL+Y7OlRKVwaXAPlNzeGkYq8QuVybQYG5blki9HdLSzfdZyFNSaNnbqEgI
21
+ 90gGbapaKX0UpEzECsovF7rTuO58UMwjL5DiI4KtWa9rGwBUppt81q/iErWQ4N1U
22
+ ChIvAx3vEhjjr648aJ/fak7nsKEJ8f1bYXGDYKIj729rggCouzpfr9+Av5TctgGu
23
+ r8mQjbj8xnvjrzUx7Dv2H+UEPacCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUp++mgRH6vjkT1Gd4pmUkI5BmiMcwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAgcW3P2LI
27
+ gdfJ9aDmowzXiwf8Z9PGt7153XqYAOOMN4qaKNSojwyFG3hcMupZTinQd8ZOJ/+b
28
+ cAhnTjkZeJEti6XYZ9yJoiqrI90d1kU6ovp1qG0eJRSyqrH9dCt/HKOVcpo1+fTr
29
+ N7q7ZWfnU9cBvOK2CXk4V01R3DYAGWVUUT+sdCmQgvQ7gkkWFo732aoWnlRabAnv
30
+ 45N1P8Qq3jxJVI9WQqGeS5l/AqPcUteVlL3Hz4FtaxduAvf9stC6GgZdNZ9t0eb1
31
+ MrilunBr0ny9pMGbDRKeTfgMh9LinxPgD3BjXqZ78prB3LDxWO8kA/yDt5sLGSiq
32
+ n8uRSvQvGormuQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-11-30 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: polyrex-headings
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.1'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.5
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.1'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.1.5
56
+ description:
57
+ email: james@r0bertson.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/pxindex.rb
63
+ homepage: https://github.com/jrobertson/pxindex
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Experimental gem to facilitate a keyword search, by querying a Polyrex document
87
+ representing a hierarchical lookup table
88
+ test_files: []
metadata.gz.sig ADDED
Binary file