loose_tight_dictionary 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/loose_tight_dictionary.rb +26 -17
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -39,9 +39,6 @@ class LooseTightDictionary
|
|
39
39
|
include Amatch
|
40
40
|
|
41
41
|
attr_reader :right_records
|
42
|
-
attr_reader :tightenings
|
43
|
-
attr_reader :identities
|
44
|
-
attr_reader :blockings
|
45
42
|
attr_reader :logger
|
46
43
|
attr_reader :tee
|
47
44
|
attr_reader :case_sensitive
|
@@ -53,9 +50,9 @@ class LooseTightDictionary
|
|
53
50
|
|
54
51
|
def initialize(right_records, options = {})
|
55
52
|
@right_records = right_records
|
56
|
-
@
|
57
|
-
@
|
58
|
-
@
|
53
|
+
@_raw_tightenings = options[:tightenings] || Array.new
|
54
|
+
@_raw_identities = options[:identities] || Array.new
|
55
|
+
@_raw_blockings = options[:blockings] || Array.new
|
59
56
|
@left_reader = options[:left_reader]
|
60
57
|
@right_reader = options[:right_reader]
|
61
58
|
@positives = options[:positives]
|
@@ -64,6 +61,20 @@ class LooseTightDictionary
|
|
64
61
|
@tee = options[:tee]
|
65
62
|
@case_sensitive = options[:case_sensitive] || false
|
66
63
|
end
|
64
|
+
|
65
|
+
# def tightenings
|
66
|
+
# def identities
|
67
|
+
# def blockings
|
68
|
+
%w{ tightenings identities blockings }.each do |name|
|
69
|
+
module_eval %{
|
70
|
+
def #{name}
|
71
|
+
@#{name} ||= @_raw_#{name}.map do |i|
|
72
|
+
next if i[0].blank?
|
73
|
+
literal_regexp i[0]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
}
|
77
|
+
end
|
67
78
|
|
68
79
|
def inline_check(left_record, right_record)
|
69
80
|
return unless positives.present? or negatives.present?
|
@@ -208,9 +219,9 @@ class LooseTightDictionary
|
|
208
219
|
return @_t_options[str] if @_t_options.andand.has_key?(str)
|
209
220
|
@_t_options ||= Hash.new
|
210
221
|
ary = Array.new
|
211
|
-
ary
|
212
|
-
tightenings.each do |
|
213
|
-
if match_data =
|
222
|
+
ary.push T.new(str, str)
|
223
|
+
tightenings.each do |regexp|
|
224
|
+
if match_data = regexp.match(str)
|
214
225
|
ary.push T.new(str, match_data.captures.compact.join)
|
215
226
|
end
|
216
227
|
end
|
@@ -239,8 +250,7 @@ class LooseTightDictionary
|
|
239
250
|
return @_i_options[str] if @_i_options.andand.has_key?(str)
|
240
251
|
@_i_options ||= Hash.new
|
241
252
|
ary = Array.new
|
242
|
-
identities.each do |
|
243
|
-
regexp = literal_regexp i[0]
|
253
|
+
identities.each do |regexp|
|
244
254
|
if regexp.match str
|
245
255
|
ary.push I.new(regexp, str, case_sensitive)
|
246
256
|
end
|
@@ -251,8 +261,7 @@ class LooseTightDictionary
|
|
251
261
|
def blocking(str)
|
252
262
|
return @_blocking[str] if @_blocking.andand.has_key?(str)
|
253
263
|
@_blocking ||= Hash.new
|
254
|
-
blockings.each do |
|
255
|
-
regexp = literal_regexp blocking[0]
|
264
|
+
blockings.each do |regexp|
|
256
265
|
if regexp.match str
|
257
266
|
return @_blocking[str] = regexp
|
258
267
|
end
|
@@ -264,10 +273,10 @@ class LooseTightDictionary
|
|
264
273
|
return @_literal_regexp[str] if @_literal_regexp.andand.has_key? str
|
265
274
|
@_literal_regexp ||= Hash.new
|
266
275
|
raw_regexp_options = str.split('/').last
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
@_literal_regexp[str] = Regexp.new str.gsub(/\A\/|\/([ixm]*)\z/, ''), (
|
276
|
+
ignore_case = (!case_sensitive or raw_regexp_options.include?('i')) ? Regexp::IGNORECASE : nil
|
277
|
+
multiline = raw_regexp_options.include?('m') ? Regexp::MULTILINE : nil
|
278
|
+
extended = raw_regexp_options.include?('x') ? Regexp::EXTENDED : nil
|
279
|
+
@_literal_regexp[str] = Regexp.new str.gsub(/\A\/|\/([ixm]*)\z/, ''), (ignore_case||multiline||extended)
|
271
280
|
end
|
272
281
|
|
273
282
|
def read_left(left_record)
|