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 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
@@ -1,6 +1,5 @@
1
1
  $: << File.expand_path(File.dirname(__FILE__))
2
+ require "komainu"
3
+ require "komainu/komainu"
2
4
  require "komainu/version"
3
5
  require "komainu/searches_text"
4
-
5
- module Komainu
6
- end
@@ -0,0 +1,5 @@
1
+ module Komainu
2
+ def self.search text, searchables
3
+ SearchesText.new(searchables).search(text)
4
+ end
5
+ end
@@ -5,5 +5,12 @@ module Komainu
5
5
  def initialize
6
6
  @items = []
7
7
  end
8
+
9
+ def to_s
10
+ {
11
+ :suggestion => suggestion,
12
+ :items => items.map { |item| item.text }
13
+ }.to_s
14
+ end
8
15
  end
9
16
  end
@@ -1,3 +1,3 @@
1
1
  module Komainu
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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.6
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: &70113471466500 !ruby/object:Gem::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: *70113471466500
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