extractsbmtags 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/MIT-LICENSE +21 -0
- data/README +68 -0
- data/Rakefile +164 -0
- data/lib/extract_sbm_tags.rb +29 -0
- data/test/test_extarct_sbm_tags.rb +77 -0
- metadata +55 -0
data/CHANGES
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2005 Aslak Hellesoy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
= ExtractSbmTags
|
2
|
+
|
3
|
+
ExtractSbmTags is RSS::RDF::Item class adds on.
|
4
|
+
This method is return array of tags using social bookmark service.
|
5
|
+
|
6
|
+
This method currently supports below services.
|
7
|
+
|
8
|
+
- del.icio.us : http://del.icio.us
|
9
|
+
- Hatena Bookmark : http://b.hatena.ne.jp
|
10
|
+
- MM/Memo : http://1470.net/mm/
|
11
|
+
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
$ sudo gem install extract_sbm_tags
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
require 'rubygems'
|
20
|
+
require "rss/1.0"
|
21
|
+
require "rss/2.0"
|
22
|
+
require "rss/dublincore"
|
23
|
+
require 'extract_sbm_tags'
|
24
|
+
|
25
|
+
content = <<EOS
|
26
|
+
<?xml version="1.0" encoding="euc-jp" ?>
|
27
|
+
- <rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="ja">
|
28
|
+
<channel rdf:about="http://www.example.com/rss">
|
29
|
+
<title>example.com</title>
|
30
|
+
<link>http://www.example.com</link>
|
31
|
+
<description>example</description>
|
32
|
+
<items>
|
33
|
+
<rdf:Seq>
|
34
|
+
<rdf:li rdf:resource="http://www.example.com/" />
|
35
|
+
</rdf:Seq>
|
36
|
+
</items>
|
37
|
+
</channel>
|
38
|
+
<item rdf:about="http://www.example.com/">
|
39
|
+
<title>example.com</title>
|
40
|
+
<link>http://www.example.com/</link>
|
41
|
+
<dc:date>2005-09-22T00:17:47+09:00</dc:date>
|
42
|
+
<dc:creator>example</dc:creator>
|
43
|
+
<dc:subject>foo bar</dc:subject>
|
44
|
+
<dc:subject>com</dc:subject>
|
45
|
+
</item>
|
46
|
+
</rdf:RDF>
|
47
|
+
EOS
|
48
|
+
|
49
|
+
rss.extract_sbm_tags(:hatena)
|
50
|
+
#=> ["foo bar", "com"]
|
51
|
+
|
52
|
+
rss.extract_sbm_tags(:delicious)
|
53
|
+
#=> ["foo", "bar"]
|
54
|
+
|
55
|
+
|
56
|
+
rss.extract_sbm_tags(:mm)
|
57
|
+
#=> ["foo bar"]
|
58
|
+
|
59
|
+
|
60
|
+
== Author
|
61
|
+
|
62
|
+
- gorou ( http://rails2u.com ) <hotchpotch@gmail.com.nospam>
|
63
|
+
- drawnboy ( http://nowherenear.net ) <drawn.boy@gmail.com.nospam>
|
64
|
+
|
65
|
+
== License
|
66
|
+
|
67
|
+
MIT License
|
68
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
$:.unshift('lib')
|
2
|
+
require 'rubygems'
|
3
|
+
require 'meta_project'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'rake/contrib/rubyforgepublisher'
|
6
|
+
require 'rake/contrib/xforge'
|
7
|
+
require 'rake/clean'
|
8
|
+
require 'rake/testtask'
|
9
|
+
require 'rake/rdoctask'
|
10
|
+
|
11
|
+
PKG_NAME = "extractsbmtags"
|
12
|
+
# Versioning scheme: MAJOR.MINOR.PATCH
|
13
|
+
# MAJOR bumps when API is broken backwards
|
14
|
+
# MINOR bumps when the API is broken backwards in a very slight/subtle (but not fatal) way
|
15
|
+
# -OR when a new release is made and propaganda is sent out.
|
16
|
+
# PATCH is bumped for every API addition and/or bugfix (ideally for every commit)
|
17
|
+
# Later DamageControl can bump PATCH automatically.
|
18
|
+
#
|
19
|
+
# (This is subject to change - AH)
|
20
|
+
#
|
21
|
+
# REMEMBER TO KEEP PKG_VERSION IN SYNC WITH CHANGELOG
|
22
|
+
PKG_VERSION = "0.1.0"
|
23
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
24
|
+
PKG_FILES = FileList[
|
25
|
+
'[A-Z]*',
|
26
|
+
'lib/**/*.rb',
|
27
|
+
'test/**/*.rb',
|
28
|
+
'examples/**/*.rb',
|
29
|
+
'doc/**/*'
|
30
|
+
]
|
31
|
+
|
32
|
+
task :default => [:test]
|
33
|
+
|
34
|
+
Rake::TestTask.new(:test) do |t|
|
35
|
+
t.libs << "test"
|
36
|
+
t.test_files = FileList['**/test*.rb']
|
37
|
+
t.verbose = true
|
38
|
+
end
|
39
|
+
|
40
|
+
# Create a task to build the RDOC documentation tree.
|
41
|
+
rd = Rake::RDocTask.new("rdoc") do |rdoc|
|
42
|
+
rdoc.rdoc_dir = 'html'
|
43
|
+
rdoc.title = "ExtractSbmTags"
|
44
|
+
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
|
45
|
+
rdoc.rdoc_files.include('README', 'CHANGES')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
|
47
|
+
rdoc.rdoc_files.exclude('doc/**/*_attrs.rdoc')
|
48
|
+
end
|
49
|
+
|
50
|
+
# ====================================================================
|
51
|
+
# Create a task that will package the Rake software into distributable
|
52
|
+
# tar, zip and gem files.
|
53
|
+
|
54
|
+
spec = Gem::Specification.new do |s|
|
55
|
+
|
56
|
+
#### Basic information.
|
57
|
+
|
58
|
+
s.name = PKG_NAME
|
59
|
+
s.version = PKG_VERSION
|
60
|
+
s.summary = "Extract social bookmark service's tags from RSS"
|
61
|
+
s.description = <<-EOF
|
62
|
+
ExtractSbmTags is RSS::RDF::Item class adds on.
|
63
|
+
This method is return array of tags using social bookmark service.
|
64
|
+
|
65
|
+
This method currently supports below services.
|
66
|
+
|
67
|
+
- del.icio.us : http://del.icio.us
|
68
|
+
- Hatena Bookmark : http://b.hatena.ne.jp
|
69
|
+
- MM/Memo : http://1470.net/mm/
|
70
|
+
EOF
|
71
|
+
|
72
|
+
s.files = PKG_FILES.to_a
|
73
|
+
s.require_path = 'lib'
|
74
|
+
|
75
|
+
#### Documentation and testing.
|
76
|
+
|
77
|
+
s.has_rdoc = true
|
78
|
+
s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
|
79
|
+
s.rdoc_options <<
|
80
|
+
'--title' << 'ExtractSbmTags' <<
|
81
|
+
'--main' << 'README' <<
|
82
|
+
'--line-numbers'
|
83
|
+
|
84
|
+
s.test_files = Dir.glob('test/test_*.rb')
|
85
|
+
|
86
|
+
#### Make executable
|
87
|
+
s.require_path = 'lib'
|
88
|
+
s.autorequire = 'spec'
|
89
|
+
|
90
|
+
#### Author and project details.
|
91
|
+
|
92
|
+
s.author = "drawnboy"
|
93
|
+
s.email = "drawn.boy@gmail.com"
|
94
|
+
s.homepage = "http://extractsbmtags.rubyforge.org"
|
95
|
+
s.rubyforge_project = "extractsbmtags"
|
96
|
+
end
|
97
|
+
|
98
|
+
desc "Build Gem"
|
99
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
100
|
+
pkg.need_zip = true
|
101
|
+
pkg.need_tar = true
|
102
|
+
end
|
103
|
+
task :gem => [:test]
|
104
|
+
|
105
|
+
# Support Tasks ------------------------------------------------------
|
106
|
+
|
107
|
+
def egrep(pattern)
|
108
|
+
Dir['**/*.rb'].each do |fn|
|
109
|
+
count = 0
|
110
|
+
open(fn) do |f|
|
111
|
+
while line = f.gets
|
112
|
+
count += 1
|
113
|
+
if line =~ pattern
|
114
|
+
puts "#{fn}:#{count}:#{line}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
desc "Look for TODO and FIXME tags in the code"
|
122
|
+
task :todo do
|
123
|
+
egrep /#.*(FIXME|TODO|TBD)/
|
124
|
+
end
|
125
|
+
|
126
|
+
task :release => [:verify_env_vars, :release_files, :publish_doc, :publish_news]
|
127
|
+
|
128
|
+
task :verify_env_vars do
|
129
|
+
raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
|
130
|
+
raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
|
131
|
+
end
|
132
|
+
|
133
|
+
task :publish_doc => [:rdoc] do
|
134
|
+
publisher = Rake::RubyForgePublisher.new(PKG_NAME, ENV['RUBYFORGE_USER'])
|
135
|
+
publisher.upload
|
136
|
+
end
|
137
|
+
|
138
|
+
desc "Release gem to RubyForge. MAKE SURE PKG_VERSION is aligned with the CHANGELOG file"
|
139
|
+
task :release_files => [:gem] do
|
140
|
+
release_files = FileList[
|
141
|
+
"pkg/#{PKG_FILE_NAME}.gem"
|
142
|
+
]
|
143
|
+
|
144
|
+
Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |xf|
|
145
|
+
# Never hardcode user name and password in the Rakefile!
|
146
|
+
xf.user_name = ENV['RUBYFORGE_USER']
|
147
|
+
xf.password = ENV['RUBYFORGE_PASSWORD']
|
148
|
+
xf.files = release_files.to_a
|
149
|
+
xf.release_name = "ExtractSbmTags #{PKG_VERSION}"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
desc "Publish news on RubyForge"
|
154
|
+
task :publish_news => [:gem] do
|
155
|
+
release_files = FileList[
|
156
|
+
"pkg/#{PKG_FILE_NAME}.gem"
|
157
|
+
]
|
158
|
+
|
159
|
+
Rake::XForge::NewsPublisher.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |news|
|
160
|
+
# Never hardcode user name and password in the Rakefile!
|
161
|
+
news.user_name = ENV['RUBYFORGE_USER']
|
162
|
+
news.password = ENV['RUBYFORGE_PASSWORD']
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RSS
|
2
|
+
class RDF
|
3
|
+
class Item
|
4
|
+
|
5
|
+
SBM_TYPE = {
|
6
|
+
:hatena => Proc.new{|x| x.map{|sbj| sbj.content}},
|
7
|
+
:delicious => /\s\s*/,
|
8
|
+
:mm => /,\s*/,
|
9
|
+
:default => Proc.new{|x| x.map{|sbj| sbj.content.split(/[\s,]\s*/)}.flatten!},
|
10
|
+
}
|
11
|
+
def extract_sbm_tags(service = :default)
|
12
|
+
return [] if self.dc_subject.nil?
|
13
|
+
|
14
|
+
service = service.to_sym
|
15
|
+
raise "need to specify service name" unless SBM_TYPE.has_key?(service)
|
16
|
+
tag = SBM_TYPE[service]
|
17
|
+
|
18
|
+
case tag
|
19
|
+
when Proc
|
20
|
+
tag.call(self.dc_subjects)
|
21
|
+
when Regexp
|
22
|
+
self.dc_subject.split(tag)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require "rss/1.0"
|
3
|
+
require "rss/2.0"
|
4
|
+
require "rss/dublincore"
|
5
|
+
require 'extract_sbm_tags'
|
6
|
+
|
7
|
+
class TestExtractSbmTags < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
content = <<EOS
|
11
|
+
<?xml version="1.0" encoding="euc-jp" ?>
|
12
|
+
- <rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="ja">
|
13
|
+
<channel rdf:about="http://www.example.com/rss">
|
14
|
+
<title>example.com</title>
|
15
|
+
<link>http://www.example.com</link>
|
16
|
+
<description>example</description>
|
17
|
+
<items>
|
18
|
+
<rdf:Seq>
|
19
|
+
<rdf:li rdf:resource="http://www.example.com/" />
|
20
|
+
</rdf:Seq>
|
21
|
+
</items>
|
22
|
+
</channel>
|
23
|
+
<item rdf:about="http://www.example.com/">
|
24
|
+
<title>example.com</title>
|
25
|
+
<link>http://www.example.com/</link>
|
26
|
+
<dc:date>2005-09-22T00:17:47+09:00</dc:date>
|
27
|
+
<dc:creator>example</dc:creator>
|
28
|
+
<dc:subject>foo bar</dc:subject>
|
29
|
+
<dc:subject>com</dc:subject>
|
30
|
+
</item>
|
31
|
+
</rdf:RDF>
|
32
|
+
EOS
|
33
|
+
@rss = RSS::Parser.parse(content)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_hatena
|
37
|
+
service = :hatena
|
38
|
+
|
39
|
+
assert_equal(
|
40
|
+
["foo bar","com"],
|
41
|
+
@rss.item(0).extract_sbm_tags(service)
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_delicious
|
46
|
+
service = :delicious
|
47
|
+
|
48
|
+
assert_equal(
|
49
|
+
["foo","bar"],
|
50
|
+
@rss.item(0).extract_sbm_tags(service)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_mm
|
55
|
+
service = :mm
|
56
|
+
|
57
|
+
assert_equal(
|
58
|
+
["foo bar"],
|
59
|
+
@rss.item(0).extract_sbm_tags(service)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_default
|
64
|
+
assert_equal(
|
65
|
+
["foo", "bar", "com"],
|
66
|
+
@rss.item(0).extract_sbm_tags()
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_invalid
|
71
|
+
service = :invalid
|
72
|
+
|
73
|
+
assert_raises(RuntimeError) do
|
74
|
+
@rss.item(0).extract_sbm_tags(service)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: extractsbmtags
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2005-10-22 00:00:00 +09:00
|
8
|
+
summary: "Extract social bookmark service's tags from RSS"
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: drawn.boy@gmail.com
|
12
|
+
homepage: http://extractsbmtags.rubyforge.org
|
13
|
+
rubyforge_project: extractsbmtags
|
14
|
+
description: "ExtractSbmTags is RSS::RDF::Item class adds on. This method is return array of
|
15
|
+
tags using social bookmark service. This method currently supports below
|
16
|
+
services. - del.icio.us : http://del.icio.us - Hatena Bookmark :
|
17
|
+
http://b.hatena.ne.jp - MM/Memo : http://1470.net/mm/"
|
18
|
+
autorequire: spec
|
19
|
+
default_executable:
|
20
|
+
bindir: bin
|
21
|
+
has_rdoc: true
|
22
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
23
|
+
requirements:
|
24
|
+
-
|
25
|
+
- ">"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.0.0
|
28
|
+
version:
|
29
|
+
platform: ruby
|
30
|
+
signing_key:
|
31
|
+
cert_chain:
|
32
|
+
authors:
|
33
|
+
- drawnboy
|
34
|
+
files:
|
35
|
+
- README
|
36
|
+
- Rakefile
|
37
|
+
- MIT-LICENSE
|
38
|
+
- CHANGES
|
39
|
+
- lib/extract_sbm_tags.rb
|
40
|
+
- test/test_extarct_sbm_tags.rb
|
41
|
+
test_files:
|
42
|
+
- test/test_extarct_sbm_tags.rb
|
43
|
+
rdoc_options:
|
44
|
+
- "--title"
|
45
|
+
- ExtractSbmTags
|
46
|
+
- "--main"
|
47
|
+
- README
|
48
|
+
- "--line-numbers"
|
49
|
+
extra_rdoc_files:
|
50
|
+
- README
|
51
|
+
- CHANGES
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
requirements: []
|
55
|
+
dependencies: []
|