polyrex-links 0.3.1 → 0.4.3

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