fuzzyhash 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
+ ---
1
2
  :build:
2
- :patch: 10
3
+ :patch: 11
3
4
  :major: 0
4
5
  :minor: 0
@@ -2,22 +2,12 @@ require 'set'
2
2
 
3
3
  class FuzzyHash
4
4
 
5
- def self.always_fuzzy(init_hash = nil)
6
- hash = new(init_hash)
7
- hash.classes_to_fuzz = nil
8
- hash
9
- end
10
-
11
- attr_accessor :classes_to_fuzz
12
-
13
- def initialize(init_hash = nil, classes_to_fuzz = nil)
5
+ def initialize(init_hash = nil)
14
6
  @fuzzies = []
15
7
  @hash_reverse = {}
16
8
  @fuzzies_reverse = {}
17
9
  @fuzzy_hash = {}
18
10
  @hash = {}
19
- @classes_to_fuzz = classes_to_fuzz || [Regexp]
20
- @classes_to_fuzz = Set.new(@classes_to_fuzz)
21
11
  init_hash.each{ |key,value| self[key] = value } if init_hash
22
12
  end
23
13
 
@@ -62,10 +52,10 @@ class FuzzyHash
62
52
  end
63
53
 
64
54
  def []=(key, value)
65
- if classes_to_fuzz.nil? || classes_to_fuzz.include?(key.class)
66
- fuzzies.delete_if{|f| f.first.hash == key.hash}
67
- fuzzies_reverse.delete_if{|k, v| v[1].hash == key.hash}
68
- hash_reverse.delete_if{|k,v| v.hash == key.hash}
55
+ if Regexp === key
56
+ fuzzies.delete_if{|f| f.first.inspect.hash == key.inspect.hash}
57
+ fuzzies_reverse.delete_if{|k, v| v[1].inspect.hash == key.inspect.hash}
58
+ hash_reverse.delete_if{|k,v| v.inspect.hash == key.inspect.hash}
69
59
 
70
60
  fuzzy_hash[key] = value
71
61
  fuzzies << [key, value]
@@ -34,6 +34,12 @@ describe "Fuzzy hash" do
34
34
  l.match_with_result('asdqweasd').should == ['qwe', 'asdqweasd']
35
35
  end
36
36
 
37
+ it "should accept regexs that match the whole strong too with the match" do
38
+ l = FuzzyHash.new
39
+ l[/asd/] = 'qwe'
40
+ l.match_with_result('asd').should == ['qwe', 'asd']
41
+ end
42
+
37
43
  it "should prefer string to regex matches" do
38
44
  l = FuzzyHash.new
39
45
  l['asd'] = 'qwe2'
@@ -59,19 +65,6 @@ describe "Fuzzy hash" do
59
65
  l['false'].should == 'everything else'
60
66
  end
61
67
 
62
- it "always fuzzy should accept .. well.. anything" do
63
- l = FuzzyHash.always_fuzzy
64
- l[1..3] = '1 to 3'
65
- l[4] = 'four'
66
- l[5..10] = '5 and up'
67
- l[/.*/] = 'whatev'
68
-
69
- l[2].should == '1 to 3'
70
- l[4].should == 'four'
71
- l[8].should == '5 and up'
72
- l['something'].should == 'whatev'
73
- end
74
-
75
68
  it "should pick between the correct regex" do
76
69
  hash = FuzzyHash.new
77
70
  hash[/^\d+$/] = 'number'
@@ -104,7 +97,7 @@ describe "Fuzzy hash" do
104
97
  l[/qwe.*/] = 'qwe2'
105
98
  l['asd'] = 'qwe'
106
99
  l['zxc'] = 'qwe'
107
- ([/qwe.*/,'asd','zxc'] & l.keys).size.should == 3
100
+ l.keys.size.should == 3
108
101
  end
109
102
 
110
103
  it "should iterate through the values" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuzzyhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-25 00:00:00 -05:00
12
+ date: 2009-12-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15