dynarex-tags 0.3.2 → 0.6.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: e7df7566e93224127b7b98989296542da0bb9b37430c6b661e077c4c4dd09b6f
4
- data.tar.gz: 823a2356aad3577df4fe21c78fee692c37535d1882973cf4b7732418341d4982
3
+ metadata.gz: 1ed697129ddcfd3a2cbfc650bc7e4828f6df0ade942a39640fc55fb764daae4f
4
+ data.tar.gz: 8e0671fcdfcd675e60030133618b63d3ea289c0a154c03a57e2d99120c3e2a6c
5
5
  SHA512:
6
- metadata.gz: ebac2e9b912fde57986cbcb31f2921d3d18d1a2b7b6d07bfff79c26dcfd93816760333cab370a370d7771eff691002e026e1569be8a491fef3d794e1cf0fac54
7
- data.tar.gz: 5e76d89817d1c23a8f6eae98a76b250faacd530c638807e0eaafeb80243fe0cf49a4cc2bc112900d231855d32aafc7ca06c414a60c8e9e5439b9d08347a75bef
6
+ metadata.gz: 26d3a75760b83cf8dcc3758c6061b6b354e84c43ed94b3010d11b3c62898ecb43af42056c8b144fc109da175917c708a1ead7be521e0dff23bdc08a653fbed07
7
+ data.tar.gz: 698fba777462534e8caf14bdcd523816f75701ac0a028d29d04f49bd6cc860f76cc3540fc39e35751348cc41f0743afdbe9d8eab6f05915feea79a9b3318a8e2
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/dynarex-tags.rb CHANGED
@@ -3,50 +3,109 @@
3
3
  # file: dynarex-tags.rb
4
4
 
5
5
  require 'dynarex'
6
- require 'fileutils'
6
+ require 'rxfreadwrite'
7
7
 
8
8
 
9
9
  class DynarexTags
10
- include RXFHelperModule
10
+ include RXFReadWriteModule
11
11
  using ColouredText
12
12
 
13
- def initialize(tags_parent_path, tagfile_xslt: nil, indexfile_xslt: nil,
13
+ def initialize(tags_parent_path, tagfile_xslt: nil, indexfile_xslt: nil,
14
14
  debug: false)
15
15
 
16
16
  puts ('tags_parent_path: ' + tags_parent_path).debug if debug
17
17
  @filepath = tags_parent_path
18
-
19
- @tagfile_xslt, @indexfile_xslt, @debug = tagfile_xslt,
18
+
19
+ @tagfile_xslt, @indexfile_xslt, @debug = tagfile_xslt,
20
20
  indexfile_xslt, debug
21
-
21
+
22
22
  @tags_path = File.join(tags_parent_path, 'tags')
23
23
  FileX.mkdir_p @tags_path
24
- @index_filename = File.join(tags_parent_path, 'dxtags.xml')
24
+ @index_filename = File.join(tags_parent_path, 'dxtags.xml')
25
25
 
26
26
  s = FileX.exists?(@index_filename) ? \
27
- @index_filename : 'tags/tag(keyword,count)'
27
+ @index_filename : 'tags/tag(keyword,count)'
28
28
 
29
29
  puts ('dxtags filepath: ' + s.inspect).debug if debug
30
- @dxindex = Dynarex.new s, json_out: false
31
- @dxindex.xslt = @indexfile_xslt if @indexfile_xslt
32
-
30
+ @dxtags = Dynarex.new s, json_out: false
31
+ @dxtags.xslt = @indexfile_xslt if @indexfile_xslt
32
+
33
+ end
34
+
35
+ def add(title: nil, url: nil)
36
+
37
+
38
+ puts ('title: ' + title.inspect).debug if @debug
39
+ puts ('url: ' + url.inspect).debug if @debug
40
+
41
+ h = @dxtags.all.inject({}) {|r,x| r.merge(x.keyword.downcase => x.count) }
42
+
43
+ a = title.scan(/(?<=\B#)[\w_]+/).uniq
44
+
45
+ a.each do |tag|
46
+
47
+ t = tag.downcase
48
+
49
+ h[t] = save_tag(h[t], t, title, url)
50
+
51
+ if @dxtags.record_exists? tag then
52
+ @dxtags.update(tag, {count: h[t]})
53
+ else
54
+ @dxtags.create({keyword: tag, count: h[t]}, id: t)
55
+ end
56
+
57
+ end
58
+
59
+ @dxtags.save @index_filename
60
+
61
+ end
62
+
63
+ def delete(title)
64
+
65
+ # find the title in each of the tags file directory
66
+ a = title.downcase.scan(/(?<=#)[\w_]+/)
67
+
68
+ a.each do |tag|
69
+
70
+ puts ("deleting tag: %s for title: %s" % [tag, title]).debug if @debug
71
+ tagfile = File.join(@tags_path, tag + '.xml')
72
+ dx = Dynarex.new(tagfile, json_out: false, autosave: true)
73
+ rx = dx.find_by_title title
74
+ rx.delete
75
+ dx.rm if dx.all.empty?
76
+
77
+ # find the title in dxtags.xml and delete it
78
+ entry = @dxtags.find tag
79
+
80
+ next unless entry
81
+
82
+ if entry.count == '1' then
83
+ entry.delete
84
+ else
85
+ entry.count = entry.count.to_i - 1
86
+ end
87
+
88
+ end
89
+
90
+ @dxtags.save @index_filename
91
+
33
92
  end
34
93
 
35
94
  def find(tag)
36
95
 
37
- rx = @dxindex.find tag.downcase
96
+ rx = @dxtags.find tag.downcase
38
97
  puts ('rx: ' + rx.inspect).debug if @debug
39
-
98
+
40
99
  if rx then
41
100
 
42
101
  tagfile = File.join(@tags_path, tag.downcase + '.xml')
43
102
  dx = Dynarex.new(tagfile, json_out: false)
44
103
  r = dx.all
45
-
104
+
46
105
  def r.to_md()
47
106
  self.map {|x| "* [%s](%s)" % [x.title, x.url]}.join("\n")
48
107
  end
49
-
108
+
50
109
  return r
51
110
 
52
111
  end
@@ -54,13 +113,13 @@ class DynarexTags
54
113
  end
55
114
 
56
115
  def generate(indexfilename=File.join(@filepath, 'index.xml'), &blk)
57
-
116
+
58
117
  dx = Dynarex.new indexfilename
59
118
 
60
- h = @dxindex.all.inject({}) {|r,x| r.merge(x.keyword => x.count) }
61
-
119
+ h = @dxtags.all.inject({}) {|r,x| r.merge(x.keyword.downcase => x.count) }
120
+
62
121
  dx.all.each do |x|
63
-
122
+
64
123
  a = if block_given? then
65
124
  blk.call(x)
66
125
  else
@@ -68,38 +127,58 @@ class DynarexTags
68
127
  .map{|tag| [tag, x.title, x.url]}
69
128
  end
70
129
 
71
- a.each {|tag, title, url| save_tag(h, tag.downcase, title, url)}
130
+ a.each do |tag, title, url|
131
+
132
+ t = tag.downcase
133
+
134
+ h[t] = save_tag(h[t], t, title, url)
135
+
136
+ end
72
137
  end
73
138
 
74
-
75
- h.each do |tag,count|
76
-
77
- if @dxindex.record_exists? tag then
78
- @dxindex.update(tag, {count: count.to_s})
139
+
140
+ h.each do |tag, count|
141
+
142
+ if @dxtags.record_exists? tag then
143
+ @dxtags.update(tag, {count: count.to_s})
79
144
  else
80
- @dxindex.create({keyword: tag, count: count.to_s}, id: tag)
145
+ @dxtags.create({keyword: tag, count: count.to_s}, id: tag.downcase)
81
146
  end
82
-
147
+
148
+ end
149
+
150
+ @dxtags.save @index_filename
151
+
152
+ end
153
+
154
+ def tags()
155
+
156
+ @dxtags.all.inject({}) do |r, x|
157
+ tagfile = File.join(@tags_path, x.keyword.downcase + '.xml')
158
+ dx = Dynarex.new(tagfile, json_out: false)
159
+ r.merge({x.keyword.downcase => dx.all.map(&:to_h)})
83
160
  end
84
161
 
85
- @dxindex.save @index_filename
162
+
86
163
  end
87
164
 
88
165
 
89
166
  private
90
167
 
91
168
 
92
- def save_tag(h, tag, title, url)
93
-
169
+ def save_tag(tag_count, tag, title, url)
170
+
171
+ puts ('tag_count: ' + tag_count.inspect).debug if @debug
94
172
  tagfile = File.join(@tags_path, tag + '.xml')
95
- buffer, h[tag] = h[tag] ? [tagfile, h[tag].succ] \
96
- : ['items/item(title,url)', '1']
173
+ buffer = tag_count ? tagfile : 'items/item(title,url)'
174
+
97
175
  dx = Dynarex.new(buffer, json_out: false)
98
176
 
99
177
  dx.xslt = @tagfile_xslt if @tagfile_xslt
100
178
  dx.create(url: url, title: title)
101
179
 
102
180
  dx.save tagfile
181
+ dx.all.length
103
182
  end
104
-
183
+
105
184
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynarex-tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,31 +11,31 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXj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9+To9mHxXszWE9gUZnfPHz6+uAUNOvVfsQ8pmQ8wOOKyS3EYk6LKaIyR
32
- ftprJ8Ncgf27HM7NI2g5+3mCd0gYPEaheYR/KMvkFdyoXPHOQEVHKFuatmc4Ck/B
33
- tKVPkKWF1ZC1D62PogcWfw2GT1mO2mGaQlc6mg2zmnF0b/5p6zbsVlB+EjfY5zKP
34
- mrhp4VTn6wlZr/M57tZbFIXbMiiBSUgOwlryzN9MzRGRp+eiFqZxUNiUHlaeeWay
35
- DWmhPViInQPjQftcVmbEJ7cSh3MAHLmEde9WXtfuVrqm7bLx2cT6gGph4MUs2CuA
36
- WkefAv1RxMCo/1hDjM5UvmJx
28
+ BgkqhkiG9w0BAQsFAAOCAYEAE6VTWAXk+ij9rjtjlzRvSIcMRHtjmvLhh8Ino6Wf
29
+ NjvKY1N3GXWVaykBpM7HGQsw2nHqw995nrqeeFEVaxoB5f8DVH0byH9KySryLuat
30
+ JZkYT+ZK4m4UompdPSN5OTcOgr7gu4oF6kGgQAMLXF3lHiM25fJhVdwBwxnZjvAg
31
+ iGM2su3faAmg4477LueW05d6cbCJ+iDHROf/PYSe9QQ4hbPrju00S8KfIDg9zOOj
32
+ A64uzZRvsfKMs8Fx2vall7sDqHcU3FhMRDZuy1OuMfQC45s7OwEE6sCjPfqvF3j0
33
+ yhIEw9ItCiYHhE6DxO518tdr6x8HgvLAjNwE2/v73Mj0gHOeMGBD5CfymYltB15y
34
+ hkZHVlLGEUPCTPfxYmdrxudsEcvYjlv8eRqwIT34hb8q/SvZ4UQ5Ep3h66ny2fBt
35
+ Gn0CkDQj+j/nOYRHXZh5P4U5CbL9ZrhpNi02sMwBYOGAfy8xGTIaDErxymeFV95A
36
+ eWFHlR8BTtTjZAXezxMFrlqp
37
37
  -----END CERTIFICATE-----
38
- date: 2018-11-03 00:00:00.000000000 Z
38
+ date: 2022-02-23 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: dynarex
@@ -43,22 +43,22 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.8'
46
+ version: '1.9'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.8.7
49
+ version: 1.9.6
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.8'
56
+ version: '1.9'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.8.7
59
+ version: 1.9.6
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,9 +83,8 @@ 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.6
86
+ rubygems_version: 3.2.22
88
87
  signing_key:
89
88
  specification_version: 4
90
- summary: dynarex-tags
89
+ summary: Uses hashtags to help reference 1 or more records from an index file.
91
90
  test_files: []
metadata.gz.sig CHANGED
Binary file