polyrex-links 0.4.3 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf7fdc48533ddbc311264c8d2c5b2db7bbeb62735373b91a9a82aa566ae50712
4
- data.tar.gz: 23804ca9e2c50c13791543c50ddb8948c16fbeb47bdbb2852f3fd94214ce5f91
3
+ metadata.gz: 79d94fb1d9b01912e3df2bb30ff533b1781e32d9843001f866a27c0f3705a762
4
+ data.tar.gz: fa362c62f93922596288dfc100b72af2ddaa78f6420ea013b4ba3cebde3bbbc9
5
5
  SHA512:
6
- metadata.gz: 598027b09384873d5ca570a66461697e9be54b6e3bfb62cc4bdcdf119f4cb63bfffd3b4fc2470da0a637d497b13acf2d6a2ba8f3dd0943965e8a0c255dbe7ca5
7
- data.tar.gz: a26a5347f38c10ad3d080a0fdd0037482f461034cb19ad7776e7181d4178472bd82cdb6514c6b7edb191a40f3f70347459ad0bcc10714d39485db81082bcbeb0
6
+ metadata.gz: 80b22de8c7dff338390fc776ded5db98ee3b37a34d24a17d236973f08f5b509a3586aa80ee855be7266d42dc2146930d958c729a057cd0b6f662edb4eb56c91a
7
+ data.tar.gz: c34db9cd5d373e8b10b21f121eec29e11b4144af71bd27f5f5b9ec9812e1b88fa5285adf4a16394d71481c76f17be591ac5097e5139a8384f4fb1bba0027b41c
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/polyrex-links.rb CHANGED
@@ -7,116 +7,120 @@ require 'polyrex'
7
7
  class PolyrexLinks < Polyrex
8
8
 
9
9
  def initialize(rawx='links/link[title,url]', delimiter: ' # ', debug: false)
10
-
11
- x, _ = RXFHelper.read(rawx)
12
- obj = x.lstrip.sub(/<\?polyrex-links\?>/,
10
+
11
+ x, _ = RXFReader.read(rawx)
12
+ obj = x.lstrip.sub(/<\?polyrex-links\?>/,
13
13
  '<?polyrex schema="links/link[title,url]" delimiter=" # "?>')
14
14
  puts 'obj: ' + x.inspect if debug
15
-
15
+
16
16
  super(obj)
17
17
  @delimiter = self.delimiter = delimiter
18
18
  @debug = debug
19
-
19
+
20
20
  end
21
-
21
+
22
22
  def find(s)
23
-
23
+
24
24
  found = find_by_link_title s
25
-
25
+
26
26
  if found then
27
-
28
- path = backtrack_path found
27
+
28
+ path = backtrack_path found
29
29
  [link(path.join('/')), path.join('/')]
30
-
30
+
31
31
  end
32
-
32
+
33
33
  end
34
-
34
+
35
35
  # returns a listing of all links sorted by title in alphabetical order
36
36
  #
37
37
  def index()
38
-
38
+
39
39
  a = []
40
40
  each_recursive {|link| a << [link.title, link.url, backtrack_path(link)] }
41
41
  a.sort_by {|title, _, _| title.downcase}
42
-
42
+
43
43
  end
44
-
44
+
45
45
  def migrate(raws)
46
-
47
- s, _ = RXFHelper.read(raws)
48
- pl = PolyrexLinks.new("<?polyrex-links?>\n\n" +
46
+
47
+ s, _ = RXFReader.read(raws)
48
+ pl = PolyrexLinks.new("<?polyrex-links?>\n\n" +
49
49
  s.sub(/<\?[^\?]+\?>/,'').lstrip)
50
-
50
+
51
51
  pl.each_recursive do |x|
52
52
  link, linkpath = find(x.title)
53
53
  x.url = link.url if link and link.url
54
54
  end
55
-
55
+
56
56
  pl
57
-
57
+
58
58
  end
59
-
59
+
60
60
  # Returns the Polyrex element for the given path
61
61
  #
62
62
  def link(s)
63
-
63
+
64
64
  self.rxpath(s.split('/').map {|x| "link[title='%s']" % x}.join('/')).first
65
-
65
+
66
66
  end
67
-
67
+
68
68
  # Returns the url and remaining arguments for the given path
69
69
  #
70
70
  def locate(raw_path)
71
-
71
+
72
72
  return nil if raw_path.nil? or raw_path.strip.empty?
73
73
  path = raw_path.sub(/^\//,'')
74
74
  a = path.split('/')
75
75
  a2 = []
76
76
  (a2 << a.clone; a.pop) while a.any?
77
77
  return nil if a2.empty?
78
-
78
+
79
79
  mask = "records/link[summary/title='%s']"
80
-
81
- begin
80
+
81
+ begin
82
82
  c = a2.shift; xpath = c.map{|x| mask % x}.join + '/summary/url/text()'
83
- r = self.element xpath
83
+ r = self.element xpath
84
84
  end until r or a2.empty?
85
-
86
- # return the found path along with any remaining string which
85
+
86
+ # return the found path along with any remaining string which
87
87
  # it didn't find, or it will return nil.
88
-
88
+
89
89
  puts "c: %s\npath: %s\nr: %s" % [c, path, r].map(&:inspect) if @debug
90
90
 
91
91
  r ? [r, path.sub(c.join('/'),'')] : nil
92
92
  end
93
-
93
+
94
94
  def save(filepath)
95
-
95
+
96
96
  super(filepath)
97
97
  export(filepath.sub(/\.xml$/,'.txt'))
98
-
98
+
99
99
  end
100
-
101
-
102
- # Return a flat Hash object containing all the links. The link path is
100
+
101
+ def search(keyword)
102
+ index().select {|x| x.first =~ /\b#{keyword}/}
103
+ end
104
+
105
+
106
+ # Return a flat Hash object containing all the links. The link path is
103
107
  # used as the key and the value is the url
104
108
  #
105
109
  def to_h()
106
-
110
+
107
111
  h = {}
108
-
112
+
109
113
  each_link {|key, value| h[key] = value }
110
114
  h
111
-
115
+
112
116
  end
113
-
117
+
114
118
  def to_s()
115
119
  "<?polyrex-links?>\n\n" + super(header: false)
116
120
  end
117
-
121
+
118
122
  private
119
-
123
+
120
124
  def backtrack_path(e, a5=[])
121
125
 
122
126
  backtrack_path(e.parent, a5) if e.parent?
@@ -124,20 +128,20 @@ class PolyrexLinks < Polyrex
124
128
 
125
129
  return a5
126
130
  end
127
-
131
+
128
132
 
129
133
  def each_link()
130
134
 
131
135
  a = []
132
-
133
- self.each_recursive() do |record, _, i|
134
-
136
+
137
+ self.each_recursive() do |record, _, i|
138
+
135
139
  a.slice!(i..-1)
136
140
  a[i] = record
137
141
  yield(a.map(&:title).join('/'), record.url) if block_given?
138
-
142
+
139
143
  end
140
-
141
- end
144
+
145
+ end
142
146
 
143
147
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyrex-links
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  5x/50O2gHQvmLgSVk8EsWqPZ6B8tMZ9h/ttCIkW33ewCmHrrxH9suuyqbC/SaiEf
36
36
  2qE86MpuEcgDiX59WiP5GiBx
37
37
  -----END CERTIFICATE-----
38
- date: 2021-06-05 00:00:00.000000000 Z
38
+ date: 2022-02-22 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: polyrex
@@ -43,20 +43,20 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.3'
46
+ version: '1.4'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.3.2
49
+ version: 1.4.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '1.3'
56
+ version: '1.4'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.3.2
59
+ version: 1.4.0
60
60
  description:
61
61
  email: digital.robertson@gmail.com
62
62
  executables: []
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.1.2
86
+ rubygems_version: 3.2.22
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: A convenient gem for retrieving a link from a hierarchical lookup table from
metadata.gz.sig CHANGED
Binary file