fuzzyhash 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION.yml +3 -3
  2. data/lib/fuzzy_hash.rb +24 -24
  3. metadata +2 -2
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
- ---
2
- :minor: 0
3
- :patch: 9
1
+ :build:
2
+ :patch: 10
4
3
  :major: 0
4
+ :minor: 0
data/lib/fuzzy_hash.rb CHANGED
@@ -4,12 +4,12 @@ class FuzzyHash
4
4
 
5
5
  def self.always_fuzzy(init_hash = nil)
6
6
  hash = new(init_hash)
7
- hash.classes_to_fuzz = nil
7
+ hash.classes_to_fuzz = nil
8
8
  hash
9
9
  end
10
-
10
+
11
11
  attr_accessor :classes_to_fuzz
12
-
12
+
13
13
  def initialize(init_hash = nil, classes_to_fuzz = nil)
14
14
  @fuzzies = []
15
15
  @hash_reverse = {}
@@ -20,47 +20,47 @@ class FuzzyHash
20
20
  @classes_to_fuzz = Set.new(@classes_to_fuzz)
21
21
  init_hash.each{ |key,value| self[key] = value } if init_hash
22
22
  end
23
-
23
+
24
24
  def clear
25
25
  hash.clear
26
26
  fuzzies.clear
27
27
  hash_reverse.clear
28
28
  fuzzies_reverse.clear
29
29
  end
30
-
30
+
31
31
  def size
32
32
  hash.size + fuzzies.size
33
33
  end
34
34
  alias_method :count, :size
35
-
36
-
35
+
36
+
37
37
  def ==(o)
38
38
  o.is_a?(FuzzyHash)
39
39
  o.send(:hash) == hash &&
40
40
  o.send(:fuzzies) == fuzzies
41
41
  end
42
-
42
+
43
43
  def empty?
44
44
  hash.empty? && fuzzies.empty?
45
45
  end
46
-
46
+
47
47
  def keys
48
48
  hash.keys + fuzzy_hash.keys
49
49
  end
50
-
50
+
51
51
  def values
52
52
  hash.values + fuzzies.collect{|r| r.last}
53
53
  end
54
-
54
+
55
55
  def each
56
56
  hash.each{|k,v| yield k,v }
57
57
  fuzzies.each{|v| yield v.first, v.last }
58
58
  end
59
-
59
+
60
60
  def delete_value(value)
61
61
  hash.delete(hash_reverse[value]) || ((rr = fuzzies_reverse[value]) && fuzzies.delete_at(rr[0]))
62
62
  end
63
-
63
+
64
64
  def []=(key, value)
65
65
  if classes_to_fuzz.nil? || classes_to_fuzz.include?(key.class)
66
66
  fuzzies.delete_if{|f| f.first.hash == key.hash}
@@ -78,7 +78,7 @@ class FuzzyHash
78
78
  end
79
79
  value
80
80
  end
81
-
81
+
82
82
  def replace(src, dest)
83
83
  if hash_reverse.key?(src)
84
84
  key = hash_reverse[src]
@@ -92,13 +92,13 @@ class FuzzyHash
92
92
  fuzzies_reverse[dest] = [rkey[0], rkey[1], dest]
93
93
  end
94
94
  end
95
-
95
+
96
96
  def [](key)
97
97
  (hash.key?(key) && hash[key]) ||
98
98
  ((lookup = fuzzy_lookup(key)) && lookup && lookup.first) ||
99
99
  fuzzy_hash[key]
100
100
  end
101
-
101
+
102
102
  def match_with_result(key)
103
103
  if hash.key?(key)
104
104
  [hash[key], key]
@@ -106,36 +106,36 @@ class FuzzyHash
106
106
  fuzzy_lookup(key)
107
107
  end
108
108
  end
109
-
109
+
110
110
  private
111
111
  attr_reader :fuzzies, :hash_reverse, :fuzzies_reverse, :hash, :fuzzy_hash
112
112
  attr_writer :fuzz_test
113
-
113
+
114
114
  def reset_fuzz_test!
115
115
  self.fuzz_test = nil
116
116
  end
117
-
117
+
118
118
  def fuzz_test
119
119
  unless @fuzz_test
120
120
  @fuzz_test = Object.new
121
121
  @fuzz_test.instance_variable_set(:'@fuzzies', fuzzies)
122
122
  method = "
123
123
  def match(str)
124
- case str
124
+ case str\n
125
125
  "
126
126
  fuzzies.each_with_index do |reg, index|
127
- method << "when #{reg.first.inspect}: [@fuzzies[#{index}][1], Regexp.last_match(0)]\n"
127
+ method << "when #{reg.first.inspect}; [@fuzzies[#{index}][1], Regexp.last_match(0)];"
128
128
  end
129
129
  method << "end\nend\n"
130
130
  @fuzz_test.instance_eval method
131
131
  end
132
132
  @fuzz_test
133
133
  end
134
-
134
+
135
135
  def fuzzy_lookup(key)
136
136
  if !fuzzies.empty? && (value = fuzz_test.match(key))
137
137
  value
138
138
  end
139
139
  end
140
-
141
- end
140
+
141
+ end
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.9
4
+ version: 0.0.10
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-10-11 00:00:00 -04:00
12
+ date: 2009-11-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15