polyrex-links 0.4.1 → 0.5.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
  SHA256:
3
- metadata.gz: 07434dc35cbabb41af50c6d49a6ef3c2fa83fd95654d04422c887c69c1653a6e
4
- data.tar.gz: fe895d84d31ebe6b12bc12f3a0a098544e9365fd070e073bfa38db78be88fea0
3
+ metadata.gz: 79d94fb1d9b01912e3df2bb30ff533b1781e32d9843001f866a27c0f3705a762
4
+ data.tar.gz: fa362c62f93922596288dfc100b72af2ddaa78f6420ea013b4ba3cebde3bbbc9
5
5
  SHA512:
6
- metadata.gz: d77dbb86612baae60a9005c570abe89b8efc2a7953cee7954e3e5ccada08f117e83a408c6fc7695409c29a109af72d5ce763d7e2ca083b13dba3e1f2cbd03339
7
- data.tar.gz: 8b4aa96fb8455b9fe8083056bb41067afadd877972fb816ab02ecc445d40a728a40d2e12452e8f5906dfb256e2965ea4241672d3f9f1062566e9dd6cab1c4a8f
6
+ metadata.gz: 80b22de8c7dff338390fc776ded5db98ee3b37a34d24a17d236973f08f5b509a3586aa80ee855be7266d42dc2146930d958c729a057cd0b6f662edb4eb56c91a
7
+ data.tar.gz: c34db9cd5d373e8b10b21f121eec29e11b4144af71bd27f5f5b9ec9812e1b88fa5285adf4a16394d71481c76f17be591ac5097e5139a8384f4fb1bba0027b41c
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/polyrex-links.rb CHANGED
@@ -6,121 +6,142 @@ require 'polyrex'
6
6
 
7
7
  class PolyrexLinks < Polyrex
8
8
 
9
- def initialize(rawx='links/link[name,url]', delimiter: ' # ', debug: false)
10
-
11
- x, _ = RXFHelper.read(rawx)
12
- obj = x.lstrip.sub(/<\?polyrex-links\?>/,
13
- '<?polyrex schema="links/link[name,url]" delimiter=" # "?>')
9
+ def initialize(rawx='links/link[title,url]', delimiter: ' # ', debug: false)
10
+
11
+ x, _ = RXFReader.read(rawx)
12
+ obj = x.lstrip.sub(/<\?polyrex-links\?>/,
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
-
24
- found = find_by_link_name s
25
-
23
+
24
+ found = find_by_link_title s
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
+ # returns a listing of all links sorted by title in alphabetical order
36
+ #
37
+ def index()
38
+
39
+ a = []
40
+ each_recursive {|link| a << [link.title, link.url, backtrack_path(link)] }
41
+ a.sort_by {|title, _, _| title.downcase}
42
+
43
+ end
44
+
35
45
  def migrate(raws)
36
-
37
- s, _ = RXFHelper.read(raws)
38
- pl = PolyrexLinks.new("<?polyrex-links?>\n\n" +
46
+
47
+ s, _ = RXFReader.read(raws)
48
+ pl = PolyrexLinks.new("<?polyrex-links?>\n\n" +
39
49
  s.sub(/<\?[^\?]+\?>/,'').lstrip)
40
-
50
+
41
51
  pl.each_recursive do |x|
42
- link, linkpath = find(x.name)
52
+ link, linkpath = find(x.title)
43
53
  x.url = link.url if link and link.url
44
54
  end
45
-
55
+
46
56
  pl
47
-
57
+
48
58
  end
49
-
59
+
50
60
  # Returns the Polyrex element for the given path
51
61
  #
52
62
  def link(s)
53
-
54
- self.rxpath(s.split('/').map {|x| "link[name='%s']" % x}.join('/')).first
55
-
63
+
64
+ self.rxpath(s.split('/').map {|x| "link[title='%s']" % x}.join('/')).first
65
+
56
66
  end
57
-
67
+
58
68
  # Returns the url and remaining arguments for the given path
59
69
  #
60
70
  def locate(raw_path)
61
-
71
+
62
72
  return nil if raw_path.nil? or raw_path.strip.empty?
63
73
  path = raw_path.sub(/^\//,'')
64
74
  a = path.split('/')
65
75
  a2 = []
66
76
  (a2 << a.clone; a.pop) while a.any?
67
77
  return nil if a2.empty?
68
-
69
- mask = "records/link[summary/name='%s']"
70
-
71
- begin
78
+
79
+ mask = "records/link[summary/title='%s']"
80
+
81
+ begin
72
82
  c = a2.shift; xpath = c.map{|x| mask % x}.join + '/summary/url/text()'
73
- r = self.element xpath
83
+ r = self.element xpath
74
84
  end until r or a2.empty?
75
-
76
- # return the found path along with any remaining string which
85
+
86
+ # return the found path along with any remaining string which
77
87
  # it didn't find, or it will return nil.
78
-
88
+
79
89
  puts "c: %s\npath: %s\nr: %s" % [c, path, r].map(&:inspect) if @debug
80
90
 
81
91
  r ? [r, path.sub(c.join('/'),'')] : nil
82
92
  end
83
-
84
-
85
- # Return a flat Hash object containing all the links. The link path is
93
+
94
+ def save(filepath)
95
+
96
+ super(filepath)
97
+ export(filepath.sub(/\.xml$/,'.txt'))
98
+
99
+ end
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
86
107
  # used as the key and the value is the url
87
108
  #
88
109
  def to_h()
89
-
110
+
90
111
  h = {}
91
-
112
+
92
113
  each_link {|key, value| h[key] = value }
93
114
  h
94
-
115
+
95
116
  end
96
-
117
+
97
118
  def to_s()
98
119
  "<?polyrex-links?>\n\n" + super(header: false)
99
120
  end
100
-
121
+
101
122
  private
102
-
123
+
103
124
  def backtrack_path(e, a5=[])
104
125
 
105
126
  backtrack_path(e.parent, a5) if e.parent?
106
- a5 << e.name
127
+ a5 << e.title
107
128
 
108
129
  return a5
109
130
  end
110
-
131
+
111
132
 
112
133
  def each_link()
113
134
 
114
135
  a = []
115
-
116
- self.each_recursive() do |record, _, i|
117
-
136
+
137
+ self.each_recursive() do |record, _, i|
138
+
118
139
  a.slice!(i..-1)
119
140
  a[i] = record
120
- yield(a.map(&:name).join('/'), record.url) if block_given?
121
-
141
+ yield(a.map(&:title).join('/'), record.url) if block_given?
142
+
122
143
  end
123
-
124
- end
144
+
145
+ end
125
146
 
126
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.1
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-05-25 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