komainu 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- require "komainu/search_result"
2
-
3
1
  module Komainu
4
2
  class SearchResults
5
3
  attr_accessor :items, :suggestion
@@ -9,11 +9,11 @@ module Komainu
9
9
 
10
10
  def search query
11
11
  results = SearchResults.new
12
- @data_to_search.each do |name, text|
13
- if text_includes_string(text, query)
14
- results.items << SearchResult.new(name, text)
15
- elsif text_includes_words_from_string(text, query)
16
- results.items << SearchResult.new(name, text)
12
+ @data_to_search.each do |searchable|
13
+ if text_includes_string(searchable.text, query)
14
+ results.items << searchable
15
+ elsif text_includes_words_from_string(searchable.text, query)
16
+ results.items << searchable
17
17
  end
18
18
  end
19
19
 
@@ -24,7 +24,7 @@ module Komainu
24
24
  private
25
25
 
26
26
  def calculate_suggestion(query)
27
- words = split_into_words(@data_to_search.values.join(" "))
27
+ words = split_into_words(@data_to_search.map { |searchable| searchable.text }.join(" "))
28
28
  levenshtein = Levenshtein.new(words)
29
29
  suggestion = split_into_words(query).map do |word|
30
30
  matches = levenshtein.search(word, 2)
@@ -1,3 +1,3 @@
1
1
  module Komainu
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -6,10 +6,13 @@ module Komainu
6
6
  subject { SearchesText.new(data_to_search) }
7
7
 
8
8
  let :data_to_search do
9
- {
10
- :item1 => "This is some text",
11
- :item2 => "Batman has no parents"
12
- }
9
+ item1 = OpenStruct.new
10
+ item1.name = :item1
11
+ item1.text = "This is some text"
12
+ item2 = OpenStruct.new
13
+ item2.name = :item2
14
+ item2.text = "Batman has no parents"
15
+ [item1, item2]
13
16
  end
14
17
 
15
18
  it "finds exact matches" do
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70232285174700 !ruby/object:Gem::Requirement
16
+ requirement: &70219264697540 !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: *70232285174700
24
+ version_requirements: *70219264697540
25
25
  description: ''
26
26
  email:
27
27
  - andrew.vos@gmail.com
@@ -35,7 +35,6 @@ files:
35
35
  - komainu.gemspec
36
36
  - lib/komainu.rb
37
37
  - lib/komainu/levenshtein.rb
38
- - lib/komainu/search_result.rb
39
38
  - lib/komainu/search_results.rb
40
39
  - lib/komainu/searches_text.rb
41
40
  - lib/komainu/trie_node.rb
@@ -1,10 +0,0 @@
1
- module Komainu
2
- class SearchResult
3
- attr_accessor :name, :text
4
-
5
- def initialize name, text
6
- @name = name
7
- @text = text
8
- end
9
- end
10
- end