kevintyll-ofac 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,4 +49,11 @@
49
49
 
50
50
  * 1 bug fix:
51
51
  * Refactored the select on OfacSdn to use the AR connection instead of building sql and using the raw connection. Fixes a bug
52
- introducted in 1.1.6 where quotes in the name raised an error.
52
+ introducted in 1.1.6 where quotes in the name raised an error.
53
+
54
+ == 1.1.9 2009-07-24
55
+
56
+ * 1 minor enhancement:
57
+ * Added a method, db_hit? for when your more concerned with speed than accuracy. db_hit? will retun true if there is an exact name match
58
+ in the ofac_sdn database. This method ignores address and city and does not produce a score.
59
+ Usage: Ofac.new({:name => 'Oscar Hernandez', :city => 'Clearwater', :address => '123 somewhere ln'}).db_hit?
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 8
3
+ :patch: 9
4
4
  :major: 1
@@ -86,6 +86,35 @@ class Ofac
86
86
  @score || calculate_score
87
87
  end
88
88
 
89
+ def db_hit?
90
+ unless @identity[:name].to_s.blank?
91
+
92
+ #first get a list from the database of possible matches by name
93
+ #this query is pretty liberal, we just want to get a list of possible
94
+ #matches from the database that we can run through our ruby matching algorithm
95
+ possible_sdns = []
96
+ name_array = process_name
97
+
98
+ name_array.delete_if{|n| n.strip.size < 2}
99
+ unless name_array.empty?
100
+ sql_name_partial = name_array.collect {|partial_name| ["name like ?", "%#{partial_name}%"]}
101
+ sql_alt_name_partial = name_array.collect {|partial_name| ["alternate_identity_name like ?", "%#{partial_name}%"]}
102
+
103
+ name_conditions = sql_name_partial.transpose
104
+ name_values = name_conditions.second
105
+ name_conditions = [name_conditions.first.join(' and ')]
106
+ alt_name_conditions = sql_alt_name_partial.transpose
107
+ alt_name_values = alt_name_conditions.second
108
+ alt_name_conditions = [alt_name_conditions.first.join(' and ')]
109
+ conditions = ["(#{name_conditions}) or (#{alt_name_conditions})"] + name_values + alt_name_values
110
+
111
+ possible_sdns = OfacSdn.find_all_by_sdn_type('individual',:select => 'name, alternate_identity_name, address, city', :conditions => conditions)
112
+
113
+ end
114
+ end
115
+ !possible_sdns.empty?
116
+ end
117
+
89
118
  # Returns an array of hashes of records in the OFAC data that found partial matches with that record's score.
90
119
  #
91
120
  # Ofac.new({:name => 'Oscar Hernandez', :city => 'Clearwater', :address => '123 somewhere ln'}).possible_hits
@@ -110,13 +139,7 @@ class Ofac
110
139
  #this query is pretty liberal, we just want to get a list of possible
111
140
  #matches from the database that we can run through our ruby matching algorithm
112
141
 
113
- #you can pass in a full name, or specify the first and last name
114
- if @identity[:name].kind_of?(Hash)
115
- name_array = [@identity[:name][:first_name],@identity[:name][:last_name]].compact
116
- else
117
- partial_name = @identity[:name].gsub(/\W/,'|')
118
- name_array = partial_name.split('|')
119
- end
142
+ name_array = process_name
120
143
 
121
144
  name_array.delete_if{|n| n.strip.size < 2}
122
145
  unless name_array.empty?
@@ -141,4 +164,14 @@ class Ofac
141
164
  return @score
142
165
  end
143
166
 
167
+ def process_name
168
+ #you can pass in a full name, or specify the first and last name
169
+ if @identity[:name].kind_of?(Hash)
170
+ name_array = [@identity[:name][:first_name],@identity[:name][:last_name]].compact
171
+ else
172
+ partial_name = @identity[:name].gsub(/\W/,'|')
173
+ name_array = partial_name.split('|')
174
+ end
175
+ end
176
+
144
177
  end
@@ -102,7 +102,7 @@ class OfacTest < Test::Unit::TestCase
102
102
  end
103
103
 
104
104
  should "return an array of possible hits" do
105
- #it should matter which order you call score or possible hits.
105
+ #it should not matter which order you call score or possible hits.
106
106
  sdn = Ofac.new({:name => 'Oscar Hernandez', :city => 'Clearwater', :address => '123 somewhere ln'})
107
107
  assert sdn.score > 0
108
108
  assert !sdn.possible_hits.empty?
@@ -111,5 +111,35 @@ class OfacTest < Test::Unit::TestCase
111
111
  assert !sdn.possible_hits.empty?
112
112
  assert sdn.score > 0
113
113
  end
114
+
115
+ should "db_hit? should return true if name is an exact match in the database" do
116
+
117
+ sdn = Ofac.new({:name => {:first_name => 'Oscar', :last_name => 'Hernandez'}, :city => 'Clearwater', :address => '123 somewhere ln'})
118
+ assert sdn.db_hit?
119
+
120
+ sdn = Ofac.new({:name => 'Oscar Hernandez', :city => 'Clearwater', :address => '123 somewhere ln'})
121
+ assert sdn.db_hit?
122
+
123
+ #single initials are ignored
124
+ sdn = Ofac.new({:name => 'Oscar M Hernandez', :city => 'Clearwater', :address => '123 somewhere ln'})
125
+ assert sdn.db_hit?
126
+
127
+ #city and address are ignored
128
+ sdn = Ofac.new({:name => 'Oscar Hernandez', :city => 'bad city', :address => 'bad address'})
129
+ assert sdn.db_hit?
130
+ end
131
+
132
+ should "db_hit? should return false if name is not an exact match in the database" do
133
+
134
+ sdn = Ofac.new({:name => {:first_name => 'Oscar', :last_name => 'de la Hernandez'}, :city => 'Clearwater', :address => '123 somewhere ln'})
135
+ assert !sdn.db_hit?
136
+
137
+ sdn = Ofac.new({:name => 'Oscar Maria Hernandez', :city => 'Clearwater', :address => '123 somewhere ln'})
138
+ assert !sdn.db_hit?
139
+
140
+ #city and address are ignored
141
+ sdn = Ofac.new({:name => 'Oscar de la Hernandez', :city => 'bad city', :address => 'bad address'})
142
+ assert !sdn.db_hit?
143
+ end
114
144
  end
115
145
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kevintyll-ofac
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Tyll
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-30 00:00:00 -07:00
12
+ date: 2009-07-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15