dynarex-tags 0.3.2 → 0.4.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: e7df7566e93224127b7b98989296542da0bb9b37430c6b661e077c4c4dd09b6f
4
- data.tar.gz: 823a2356aad3577df4fe21c78fee692c37535d1882973cf4b7732418341d4982
3
+ metadata.gz: 35c3f170ed1082dbbd4151235bfbc30fc54b175c9b0d711768406d0293e06ee4
4
+ data.tar.gz: 37784fc281759926b994b669896d5c332a830e99c90f9147f8f4b7d1f646446a
5
5
  SHA512:
6
- metadata.gz: ebac2e9b912fde57986cbcb31f2921d3d18d1a2b7b6d07bfff79c26dcfd93816760333cab370a370d7771eff691002e026e1569be8a491fef3d794e1cf0fac54
7
- data.tar.gz: 5e76d89817d1c23a8f6eae98a76b250faacd530c638807e0eaafeb80243fe0cf49a4cc2bc112900d231855d32aafc7ca06c414a60c8e9e5439b9d08347a75bef
6
+ metadata.gz: ea1e944d2a168ac6a5a4b3ca36f9956e6473a1a832ee5cf822c3d9084875b322f48e5385d8f8432972fa72851a044c62143aff7182c7194dd90f8c2d2bd93719
7
+ data.tar.gz: bf7a6130f746afcb5536f470e99e0d0870ed965a8903421bff3b4b044e5bc3ea11f999f04fb03de46cbc47a9744426a98bc364dc04994628b426c41a2a8f157d
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -27,14 +27,73 @@ class DynarexTags
27
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
30
+ @dxtags = Dynarex.new s, json_out: false
31
+ @dxtags.xslt = @indexfile_xslt if @indexfile_xslt
32
32
 
33
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
+
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
@@ -57,7 +116,7 @@ class DynarexTags
57
116
 
58
117
  dx = Dynarex.new indexfilename
59
118
 
60
- h = @dxindex.all.inject({}) {|r,x| r.merge(x.keyword => x.count) }
119
+ h = @dxtags.all.inject({}) {|r,x| r.merge(x.keyword.downcase => x.count) }
61
120
 
62
121
  dx.all.each do |x|
63
122
 
@@ -68,38 +127,47 @@ 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
139
 
75
- h.each do |tag,count|
140
+ h.each do |tag, count|
76
141
 
77
- if @dxindex.record_exists? tag then
78
- @dxindex.update(tag, {count: count.to_s})
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
 
83
148
  end
149
+
150
+ @dxtags.save @index_filename
84
151
 
85
- @dxindex.save @index_filename
86
- end
152
+ end
87
153
 
88
154
 
89
155
  private
90
156
 
91
157
 
92
- def save_tag(h, tag, title, url)
158
+ def save_tag(tag_count, tag, title, url)
93
159
 
160
+ puts ('tag_count: ' + tag_count.inspect).debug if @debug
94
161
  tagfile = File.join(@tags_path, tag + '.xml')
95
- buffer, h[tag] = h[tag] ? [tagfile, h[tag].succ] \
96
- : ['items/item(title,url)', '1']
162
+ buffer = tag_count ? tagfile : 'items/item(title,url)'
163
+
97
164
  dx = Dynarex.new(buffer, json_out: false)
98
165
 
99
166
  dx.xslt = @tagfile_xslt if @tagfile_xslt
100
167
  dx.create(url: url, title: title)
101
168
 
102
169
  dx.save tagfile
170
+ dx.all.length
103
171
  end
104
172
 
105
173
  end
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.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  DWmhPViInQPjQftcVmbEJ7cSh3MAHLmEde9WXtfuVrqm7bLx2cT6gGph4MUs2CuA
36
36
  WkefAv1RxMCo/1hDjM5UvmJx
37
37
  -----END CERTIFICATE-----
38
- date: 2018-11-03 00:00:00.000000000 Z
38
+ date: 2018-11-04 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: dynarex
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '1.8'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.8.7
49
+ version: 1.8.10
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,7 +56,7 @@ dependencies:
56
56
  version: '1.8'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.8.7
59
+ version: 1.8.10
60
60
  description:
61
61
  email: james@jamesrobertson.eu
62
62
  executables: []
@@ -87,5 +87,5 @@ rubyforge_project:
87
87
  rubygems_version: 2.7.6
88
88
  signing_key:
89
89
  specification_version: 4
90
- summary: dynarex-tags
90
+ summary: Uses hashtags to help reference 1 or more records from an index file.
91
91
  test_files: []
metadata.gz.sig CHANGED
Binary file