fuzzyhash 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/VERSION.yml +1 -1
  2. data/lib/fuzzy_hash.rb +10 -6
  3. metadata +1 -1
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 8
3
+ :patch: 9
4
4
  :major: 0
data/lib/fuzzy_hash.rb CHANGED
@@ -14,6 +14,7 @@ class FuzzyHash
14
14
  @fuzzies = []
15
15
  @hash_reverse = {}
16
16
  @fuzzies_reverse = {}
17
+ @fuzzy_hash = {}
17
18
  @hash = {}
18
19
  @classes_to_fuzz = classes_to_fuzz || [Regexp]
19
20
  @classes_to_fuzz = Set.new(@classes_to_fuzz)
@@ -44,7 +45,7 @@ class FuzzyHash
44
45
  end
45
46
 
46
47
  def keys
47
- hash.keys + fuzzies.collect{|r| r.first}
48
+ hash.keys + fuzzy_hash.keys
48
49
  end
49
50
 
50
51
  def values
@@ -63,8 +64,10 @@ class FuzzyHash
63
64
  def []=(key, value)
64
65
  if classes_to_fuzz.nil? || classes_to_fuzz.include?(key.class)
65
66
  fuzzies.delete_if{|f| f.first.hash == key.hash}
66
- fuzzies_reverse.delete_if{|k, v| v.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}
67
69
 
70
+ fuzzy_hash[key] = value
68
71
  fuzzies << [key, value]
69
72
  reset_fuzz_test!
70
73
  fuzzies_reverse[value] = [fuzzies.size - 1, key, value]
@@ -91,7 +94,9 @@ class FuzzyHash
91
94
  end
92
95
 
93
96
  def [](key)
94
- hash.key?(key) ? hash[key] : (lookup = fuzzy_lookup(key)) && lookup && lookup.first
97
+ (hash.key?(key) && hash[key]) ||
98
+ ((lookup = fuzzy_lookup(key)) && lookup && lookup.first) ||
99
+ fuzzy_hash[key]
95
100
  end
96
101
 
97
102
  def match_with_result(key)
@@ -103,7 +108,7 @@ class FuzzyHash
103
108
  end
104
109
 
105
110
  private
106
- attr_reader :fuzzies, :hash_reverse, :fuzzies_reverse, :hash
111
+ attr_reader :fuzzies, :hash_reverse, :fuzzies_reverse, :hash, :fuzzy_hash
107
112
  attr_writer :fuzz_test
108
113
 
109
114
  def reset_fuzz_test!
@@ -119,10 +124,9 @@ class FuzzyHash
119
124
  case str
120
125
  "
121
126
  fuzzies.each_with_index do |reg, index|
122
- method << "when #{reg.first.inspect}: [@fuzzies[#{index}][1], str]\n"
127
+ method << "when #{reg.first.inspect}: [@fuzzies[#{index}][1], Regexp.last_match(0)]\n"
123
128
  end
124
129
  method << "end\nend\n"
125
-
126
130
  @fuzz_test.instance_eval method
127
131
  end
128
132
  @fuzz_test
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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull