loose_tight_dictionary 0.0.2 → 0.0.3

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 +1 -1
  2. data/lib/loose_tight_dictionary.rb +26 -17
  3. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
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
- @tightenings = options[:tightenings] || Array.new
57
- @identities = options[:identities] || Array.new
58
- @blockings = options[:blockings] || Array.new
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 << T.new(str, str)
212
- tightenings.each do |i|
213
- if match_data = literal_regexp(i[0]).match(str)
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 |i|
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 |blocking|
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
- i = (!case_sensitive or raw_regexp_options.include?('i')) ? Regexp::IGNORECASE : nil
268
- m = raw_regexp_options.include?('m') ? Regexp::MULTILINE : nil
269
- x = raw_regexp_options.include?('x') ? Regexp::EXTENDED : nil
270
- @_literal_regexp[str] = Regexp.new str.gsub(/\A\/|\/([ixm]*)\z/, ''), (i||m||x), 'U'
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)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Seamus Abshere