komainu 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -0
- data/README.md.docu +32 -0
- data/Rakefile +36 -0
- data/lib/komainu.rb +2 -3
- data/lib/komainu/komainu.rb +5 -0
- data/lib/komainu/search_results.rb +7 -0
- data/lib/komainu/version.rb +1 -1
- data/spec/komainu/komainu_spec.rb +11 -0
- metadata +8 -3
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
komainu
|
2
|
+
=======
|
3
|
+
|
4
|
+
A very simple text search tool.
|
5
|
+
|
6
|
+
|
7
|
+
## Examples
|
8
|
+
|
9
|
+
### Simple Search
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
item1 = OpenStruct.new
|
13
|
+
item1.text = "hello"
|
14
|
+
item2 = OpenStruct.new
|
15
|
+
item2.text = "world"
|
16
|
+
searchables = [item1, item2]
|
17
|
+
Komainu.search("world", searchables)
|
18
|
+
|
19
|
+
#=> {:suggestion=>nil, :items=>["world"]}
|
20
|
+
```
|
21
|
+
|
22
|
+
### Suggestions
|
23
|
+
```ruby
|
24
|
+
item = OpenStruct.new
|
25
|
+
item.text = "Batman has no parents :("
|
26
|
+
searchables = [item]
|
27
|
+
Komainu.search("bertman", searchables)
|
28
|
+
|
29
|
+
#=> {:suggestion=>"Batman", :items=>[]}
|
30
|
+
```
|
data/README.md.docu
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
komainu
|
2
|
+
=======
|
3
|
+
|
4
|
+
A very simple text search tool.
|
5
|
+
|
6
|
+
|
7
|
+
## Examples
|
8
|
+
|
9
|
+
### Simple Search
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
:example:
|
13
|
+
item1 = OpenStruct.new
|
14
|
+
item1.text = "hello"
|
15
|
+
item2 = OpenStruct.new
|
16
|
+
item2.text = "world"
|
17
|
+
searchables = [item1, item2]
|
18
|
+
Komainu.search("world", searchables)
|
19
|
+
|
20
|
+
#=> {:suggestion=>nil, :items=>["world"]}
|
21
|
+
:end:
|
22
|
+
```
|
23
|
+
|
24
|
+
### Suggestions
|
25
|
+
```ruby
|
26
|
+
item = OpenStruct.new
|
27
|
+
item.text = "Batman has no parents :("
|
28
|
+
searchables = [item]
|
29
|
+
Komainu.search("bertman", searchables)
|
30
|
+
|
31
|
+
#=> {:suggestion=>"Batman", :items=>[]}
|
32
|
+
```
|
data/Rakefile
CHANGED
@@ -4,3 +4,39 @@ require 'rake/testtask'
|
|
4
4
|
Rake::TestTask.new(:spec) do |task|
|
5
5
|
task.test_files = FileList['spec/**/*_spec.rb']
|
6
6
|
end
|
7
|
+
|
8
|
+
task :execute_examples do
|
9
|
+
execute_examples("README.md.docu")
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute_examples(file)
|
13
|
+
require "komainu"
|
14
|
+
puts "Executing Examples..."
|
15
|
+
errors = []
|
16
|
+
contents = File.read(file)
|
17
|
+
contents.scan(/:example:((?:(?!^:end:).)*)/m).flatten.each do |example|
|
18
|
+
if example.include?("#=>")
|
19
|
+
expected = example.scan(/#=>\s*(.*)/).first.first
|
20
|
+
actual = eval(example).inspect
|
21
|
+
if actual == expected
|
22
|
+
print "."
|
23
|
+
else
|
24
|
+
print "F"
|
25
|
+
errors << "Assertion does not match example. Expected \"#{actual}\" to equal \"#{expected}\"."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
puts
|
30
|
+
|
31
|
+
if errors.any?
|
32
|
+
errors.each do |error|
|
33
|
+
puts error
|
34
|
+
end
|
35
|
+
exit 1
|
36
|
+
else
|
37
|
+
puts "All examples passed!"
|
38
|
+
File.open(file.chomp(File.extname(file)), "w") do |file|
|
39
|
+
file.write contents.gsub(":example:\n", "").gsub(":end:\n", "")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/komainu.rb
CHANGED
data/lib/komainu/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
+
require "komainu/komainu"
|
3
|
+
module Komainu
|
4
|
+
describe Komainu do
|
5
|
+
it "searches" do
|
6
|
+
item = OpenStruct.new
|
7
|
+
item.text = "hello"
|
8
|
+
Komainu.search("hello", [item]).must_be_kind_of SearchResults
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: komainu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-23 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &70148385079500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70148385079500
|
25
25
|
description: ''
|
26
26
|
email:
|
27
27
|
- andrew.vos@gmail.com
|
@@ -31,14 +31,18 @@ extra_rdoc_files: []
|
|
31
31
|
files:
|
32
32
|
- .gitignore
|
33
33
|
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- README.md.docu
|
34
36
|
- Rakefile
|
35
37
|
- komainu.gemspec
|
36
38
|
- lib/komainu.rb
|
39
|
+
- lib/komainu/komainu.rb
|
37
40
|
- lib/komainu/levenshtein.rb
|
38
41
|
- lib/komainu/search_results.rb
|
39
42
|
- lib/komainu/searches_text.rb
|
40
43
|
- lib/komainu/trie_node.rb
|
41
44
|
- lib/komainu/version.rb
|
45
|
+
- spec/komainu/komainu_spec.rb
|
42
46
|
- spec/komainu/levenshtein_spec.rb
|
43
47
|
- spec/komainu/searches_text_spec.rb
|
44
48
|
- spec/komainu/trie_node_spec.rb
|
@@ -68,6 +72,7 @@ signing_key:
|
|
68
72
|
specification_version: 3
|
69
73
|
summary: ''
|
70
74
|
test_files:
|
75
|
+
- spec/komainu/komainu_spec.rb
|
71
76
|
- spec/komainu/levenshtein_spec.rb
|
72
77
|
- spec/komainu/searches_text_spec.rb
|
73
78
|
- spec/komainu/trie_node_spec.rb
|