dynarex-tags 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dynarex-tags.rb +47 -31
- metadata +2 -2
data/lib/dynarex-tags.rb
CHANGED
@@ -7,55 +7,71 @@ require 'fileutils'
|
|
7
7
|
|
8
8
|
class DynarexTags
|
9
9
|
|
10
|
-
def initialize(tags_path
|
10
|
+
def initialize(tags_path)
|
11
11
|
|
12
12
|
FileUtils.mkdir_p tags_path
|
13
13
|
Dir.chdir tags_path
|
14
|
-
index_filename = File.join(tags_path, '
|
14
|
+
@index_filename = File.join(tags_path, '_dynarextags.xml')
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
dynarex = Dynarex.new index_filename
|
18
|
-
else
|
19
|
-
dynarex = Dynarex.new('tags/tag(keyword,count)')
|
20
|
-
dynarex.save index_filename, pretty: true
|
21
|
-
end
|
17
|
+
def generate(category_url)
|
22
18
|
|
19
|
+
h = {}
|
23
20
|
category_dynarex = Dynarex.new category_url
|
24
21
|
|
25
|
-
|
26
|
-
|
22
|
+
category_dynarex.to_h.each do |item|
|
23
|
+
|
24
|
+
title, url = item.values
|
25
|
+
title.scan(/#(\w+)/).flatten.each {|tag| save_tag(h, tag, title, url)}
|
26
|
+
end
|
27
|
+
|
28
|
+
save_dynarex_index(h)
|
29
|
+
end
|
30
|
+
|
31
|
+
def save_title_tags(title, url)
|
27
32
|
|
28
|
-
|
33
|
+
if File.exists? @index_filename then
|
34
|
+
dynarex = Dynarex.new @index_filename
|
35
|
+
else
|
36
|
+
dynarex = Dynarex.new('tags/tag(keyword,count)')
|
37
|
+
dynarex.save @index_filename, pretty: true
|
38
|
+
end
|
29
39
|
|
30
|
-
|
40
|
+
h = dynarex.flat_records.inject({}) do |r,x|
|
41
|
+
r.merge({x[:keyword] => x[:count].to_i})
|
42
|
+
end
|
31
43
|
|
32
|
-
|
44
|
+
title.scan(/#(\w+)/).flatten.each {|tag| save_tag(h,tag, title, url)}
|
45
|
+
save_dynarex_index(h)
|
46
|
+
end
|
33
47
|
|
34
|
-
|
35
|
-
tagfile = tag + '.xml'
|
48
|
+
private
|
36
49
|
|
37
|
-
|
50
|
+
def save_dynarex_index(h)
|
51
|
+
|
52
|
+
dynarex = Dynarex.new('tags/tag(keyword,count)')
|
53
|
+
h.each {|tag,count| dynarex.create keyword: tag, count: count.to_s}
|
54
|
+
dynarex.save @index_filename, pretty: true
|
55
|
+
end
|
38
56
|
|
39
|
-
|
40
|
-
dyn = Dynarex.new(tagfile)
|
41
|
-
dyn.create(url: url, title: title)
|
42
|
-
dyn.save tagfile, pretty: true
|
43
|
-
dyn = nil
|
57
|
+
def save_tag(h, tag, title, url)
|
44
58
|
|
45
|
-
|
59
|
+
rec = h[tag]
|
60
|
+
tagfile = tag + '.xml'
|
46
61
|
|
47
|
-
|
62
|
+
if rec then
|
48
63
|
|
49
|
-
|
50
|
-
|
51
|
-
dyn.save tagfile, pretty: true
|
52
|
-
dyn = nil
|
64
|
+
h[tag] += 1
|
65
|
+
dyn = Dynarex.new(tagfile)
|
53
66
|
|
54
|
-
|
67
|
+
else
|
55
68
|
|
56
|
-
|
69
|
+
h[tag] = 1
|
70
|
+
dyn = Dynarex.new('items/item(title,url)')
|
57
71
|
end
|
58
|
-
dynarex.save index_filename, pretty: true
|
59
72
|
|
73
|
+
dyn.create(url: url, title: title)
|
74
|
+
dyn.save tagfile, pretty: true
|
60
75
|
end
|
61
|
-
|
76
|
+
|
77
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dynarex-tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-22 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dynarex
|