dynarex-tags 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/dynarex-tags.rb +61 -0
  2. metadata +64 -0
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: dynarex-tags.rb
4
+
5
+ require 'dynarex'
6
+ require 'fileutils'
7
+
8
+ class DynarexTags
9
+
10
+ def initialize(tags_path, category_url)
11
+
12
+ FileUtils.mkdir_p tags_path
13
+ Dir.chdir tags_path
14
+ index_filename = File.join(tags_path, 'dynarextags.xml')
15
+
16
+ if File.exists? index_filename then
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
22
+
23
+ category_dynarex = Dynarex.new category_url
24
+
25
+ a = category_dynarex.to_h.map {|item| item.values}
26
+ category_dynarex = nil
27
+
28
+ a.each do |title, url|
29
+
30
+ a2 = title.scan(/#(\w+)/).flatten
31
+
32
+ a2.each do |tag|
33
+
34
+ rec = dynarex.find_by_keyword tag
35
+ tagfile = tag + '.xml'
36
+
37
+ if rec then
38
+
39
+ rec.count = rec.count.succ
40
+ dyn = Dynarex.new(tagfile)
41
+ dyn.create(url: url, title: title)
42
+ dyn.save tagfile, pretty: true
43
+ dyn = nil
44
+
45
+ else
46
+
47
+ dynarex.create keyword: tag, count: '1'
48
+
49
+ dyn = Dynarex.new('items/item(title,url)')
50
+ dyn.create(url: url, title: title)
51
+ dyn.save tagfile, pretty: true
52
+ dyn = nil
53
+
54
+ end
55
+
56
+ end
57
+ end
58
+ dynarex.save index_filename, pretty: true
59
+
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynarex-tags
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - James Robertson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-11-12 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dynarex
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description:
27
+ email:
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - lib/dynarex-tags.rb
36
+ homepage:
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.23
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: dynarex-tags
63
+ test_files: []
64
+