tsukasaoishi-kaerukeyword 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/Manifest.txt +5 -0
- data/README.rdoc +56 -0
- data/Rakefile +24 -0
- data/lib/kaerukeyword.rb +79 -0
- metadata +80 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= kaerukeyword
|
2
|
+
|
3
|
+
= Description
|
4
|
+
KaeruKeyword は登録されたキーワードが文中に存在
|
5
|
+
するかどうかを調べることができます。
|
6
|
+
|
7
|
+
|
8
|
+
インスタンスの作成時にキーワードを登録できます。
|
9
|
+
|
10
|
+
keywords = KaeruKeyword.new(["Ruby", "Rails"])
|
11
|
+
|
12
|
+
|
13
|
+
あとからキーワードを追加することもできます。
|
14
|
+
|
15
|
+
keywords << "Tsukasa"
|
16
|
+
|
17
|
+
|
18
|
+
searchメソッドで文中からキーワードを探し出します。
|
19
|
+
キーワードが見つかったときは、そのキーワードを
|
20
|
+
含めた配列を返します。
|
21
|
+
|
22
|
+
keywords.search("I Love Ruby") #=> ["Ruby"]
|
23
|
+
|
24
|
+
|
25
|
+
== REQUIREMENTS:
|
26
|
+
|
27
|
+
Hpricot
|
28
|
+
|
29
|
+
== INSTALL:
|
30
|
+
|
31
|
+
sudo gem install tsukasaoishi-kaerukeyword
|
32
|
+
|
33
|
+
== LICENSE:
|
34
|
+
|
35
|
+
(The MIT License)
|
36
|
+
|
37
|
+
Copyright (c) 2009 Tsukasa OISHI
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
'Software'), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
53
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
54
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
55
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
56
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/kaerukeyword'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('kaerukeyword', Kaerukeyword::VERSION) do |p|
|
7
|
+
p.developer('FIXME full name', 'FIXME email')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.rubyforge_name = p.name # TODO this is default value
|
10
|
+
p.extra_dev_deps = [
|
11
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
12
|
+
]
|
13
|
+
|
14
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
15
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
16
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
17
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
21
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
22
|
+
|
23
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
24
|
+
# task :default => [:spec, :features]
|
data/lib/kaerukeyword.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
#
|
5
|
+
# KaeruKeyword
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# KaeruKeyword は登録されたキーワードが文中に存在
|
9
|
+
# するかどうかを調べることができます。
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# インスタンスの作成時にキーワードを登録できます。
|
13
|
+
#
|
14
|
+
# keywords = KaeruKeyword.new(["Ruby", "Rails"])
|
15
|
+
#
|
16
|
+
#
|
17
|
+
# あとからキーワードを追加することもできます。
|
18
|
+
#
|
19
|
+
# keywords << "Tsukasa"
|
20
|
+
#
|
21
|
+
#
|
22
|
+
# searchメソッドで文中からキーワードを探し出します。
|
23
|
+
# キーワードが見つかったときは、そのキーワードを
|
24
|
+
# 含めた配列を返します。
|
25
|
+
#
|
26
|
+
# keywords.search("I Love Ruby") #=> ["Ruby"]
|
27
|
+
#
|
28
|
+
#
|
29
|
+
#
|
30
|
+
# Copyright 2008 (c) Tsukasa OISHI, under MIT License.
|
31
|
+
#
|
32
|
+
# おおいしつかさ
|
33
|
+
# http://www.kaeruspoon.net
|
34
|
+
#
|
35
|
+
#
|
36
|
+
class Kaerukeyword
|
37
|
+
VERSION = '1.0.1'
|
38
|
+
|
39
|
+
def initialize(key_array = nil)
|
40
|
+
@tree = {}
|
41
|
+
key_array.each {|k| add(k)} if key_array.is_a?(Array)
|
42
|
+
end
|
43
|
+
|
44
|
+
def add(key)
|
45
|
+
now = @tree
|
46
|
+
key.split(//).each do |c|
|
47
|
+
now[c] = {} unless now.has_key? c
|
48
|
+
now = now[c]
|
49
|
+
end
|
50
|
+
now[:end] = key
|
51
|
+
end
|
52
|
+
alias :<< :add
|
53
|
+
|
54
|
+
def search(text)
|
55
|
+
list = []
|
56
|
+
word = ""
|
57
|
+
now = @tree
|
58
|
+
text.split(//).each do |c|
|
59
|
+
unless now.has_key? c
|
60
|
+
unless word.empty?
|
61
|
+
list << word
|
62
|
+
word = ""
|
63
|
+
end
|
64
|
+
now = @tree
|
65
|
+
end
|
66
|
+
|
67
|
+
if now.has_key? c
|
68
|
+
now = now[c]
|
69
|
+
word = now[:end] if now[:end]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
unless word.empty?
|
74
|
+
list << word
|
75
|
+
end
|
76
|
+
|
77
|
+
list
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tsukasaoishi-kaerukeyword
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- FIXME full name
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-07 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: newgem
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
version:
|
35
|
+
description: "KaeruKeyword \xE3\x81\xAF\xE7\x99\xBB\xE9\x8C\xB2\xE3\x81\x95\xE3\x82\x8C\xE3\x81\x9F\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x81\x8C\xE6\x96\x87\xE4\xB8\xAD\xE3\x81\xAB\xE5\xAD\x98\xE5\x9C\xA8 \xE3\x81\x99\xE3\x82\x8B\xE3\x81\x8B\xE3\x81\xA9\xE3\x81\x86\xE3\x81\x8B\xE3\x82\x92\xE8\xAA\xBF\xE3\x81\xB9\xE3\x82\x8B\xE3\x81\x93\xE3\x81\xA8\xE3\x81\x8C\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 \xE3\x82\xA4\xE3\x83\xB3\xE3\x82\xB9\xE3\x82\xBF\xE3\x83\xB3\xE3\x82\xB9\xE3\x81\xAE\xE4\xBD\x9C\xE6\x88\x90\xE6\x99\x82\xE3\x81\xAB\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x82\x92\xE7\x99\xBB\xE9\x8C\xB2\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 keywords = KaeruKeyword.new([\"Ruby\", \"Rails\"]) \xE3\x81\x82\xE3\x81\xA8\xE3\x81\x8B\xE3\x82\x89\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x82\x92\xE8\xBF\xBD\xE5\x8A\xA0\xE3\x81\x99\xE3\x82\x8B\xE3\x81\x93\xE3\x81\xA8\xE3\x82\x82\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 keywords << \"Tsukasa\" search\xE3\x83\xA1\xE3\x82\xBD\xE3\x83\x83\xE3\x83\x89\xE3\x81\xA7\xE6\x96\x87\xE4\xB8\xAD\xE3\x81\x8B\xE3\x82\x89\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x82\x92\xE6\x8E\xA2\xE3\x81\x97\xE5\x87\xBA\xE3\x81\x97\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 \xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x81\x8C\xE8\xA6\x8B\xE3\x81\xA4\xE3\x81\x8B\xE3\x81\xA3\xE3\x81\x9F\xE3\x81\xA8\xE3\x81\x8D\xE3\x81\xAF\xE3\x80\x81\xE3\x81\x9D\xE3\x81\xAE\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x82\x92 \xE5\x90\xAB\xE3\x82\x81\xE3\x81\x9F\xE9\x85\x8D\xE5\x88\x97\xE3\x82\x92\xE8\xBF\x94\xE3\x81\x97\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 keywords.search(\"I Love Ruby\") #=> [\"Ruby\"]"
|
36
|
+
email:
|
37
|
+
- FIXME email
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- History.txt
|
48
|
+
- Manifest.txt
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- lib/kaerukeyword.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage:
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --main
|
57
|
+
- README.rdoc
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project: kaerukeyword
|
75
|
+
rubygems_version: 1.2.0
|
76
|
+
signing_key:
|
77
|
+
specification_version: 2
|
78
|
+
summary: "KaeruKeyword \xE3\x81\xAF\xE7\x99\xBB\xE9\x8C\xB2\xE3\x81\x95\xE3\x82\x8C\xE3\x81\x9F\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x81\x8C\xE6\x96\x87\xE4\xB8\xAD\xE3\x81\xAB\xE5\xAD\x98\xE5\x9C\xA8 \xE3\x81\x99\xE3\x82\x8B\xE3\x81\x8B\xE3\x81\xA9\xE3\x81\x86\xE3\x81\x8B\xE3\x82\x92\xE8\xAA\xBF\xE3\x81\xB9\xE3\x82\x8B\xE3\x81\x93\xE3\x81\xA8\xE3\x81\x8C\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 \xE3\x82\xA4\xE3\x83\xB3\xE3\x82\xB9\xE3\x82\xBF\xE3\x83\xB3\xE3\x82\xB9\xE3\x81\xAE\xE4\xBD\x9C\xE6\x88\x90\xE6\x99\x82\xE3\x81\xAB\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x82\x92\xE7\x99\xBB\xE9\x8C\xB2\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 keywords = KaeruKeyword.new([\"Ruby\", \"Rails\"]) \xE3\x81\x82\xE3\x81\xA8\xE3\x81\x8B\xE3\x82\x89\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x82\x92\xE8\xBF\xBD\xE5\x8A\xA0\xE3\x81\x99\xE3\x82\x8B\xE3\x81\x93\xE3\x81\xA8\xE3\x82\x82\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 keywords << \"Tsukasa\" search\xE3\x83\xA1\xE3\x82\xBD\xE3\x83\x83\xE3\x83\x89\xE3\x81\xA7\xE6\x96\x87\xE4\xB8\xAD\xE3\x81\x8B\xE3\x82\x89\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x82\x92\xE6\x8E\xA2\xE3\x81\x97\xE5\x87\xBA\xE3\x81\x97\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 \xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x81\x8C\xE8\xA6\x8B\xE3\x81\xA4\xE3\x81\x8B\xE3\x81\xA3\xE3\x81\x9F\xE3\x81\xA8\xE3\x81\x8D\xE3\x81\xAF\xE3\x80\x81\xE3\x81\x9D\xE3\x81\xAE\xE3\x82\xAD\xE3\x83\xBC\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x82\x92 \xE5\x90\xAB\xE3\x82\x81\xE3\x81\x9F\xE9\x85\x8D\xE5\x88\x97\xE3\x82\x92\xE8\xBF\x94\xE3\x81\x97\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 keywords.search(\"I Love Ruby\") #=> [\"Ruby\"]"
|
79
|
+
test_files: []
|
80
|
+
|