ofac 1.2.3 → 1.2.4

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 (52) hide show
  1. data/History.txt +5 -0
  2. data/Rakefile +2 -1
  3. data/VERSION.yml +1 -1
  4. data/lib/ofac/models/ofac_sdn_loader.rb +61 -56
  5. data/ofac.gemspec +50 -13
  6. data/rdoc/Ofac.html +423 -0
  7. data/rdoc/OfacMatch.html +282 -0
  8. data/rdoc/OfacSdn.html +133 -0
  9. data/rdoc/OfacSdnLoader.html +225 -0
  10. data/rdoc/README_rdoc.html +267 -0
  11. data/rdoc/String.html +245 -0
  12. data/rdoc/created.rid +8 -1
  13. data/rdoc/images/add.png +0 -0
  14. data/rdoc/images/brick.png +0 -0
  15. data/rdoc/images/brick_link.png +0 -0
  16. data/rdoc/images/bug.png +0 -0
  17. data/rdoc/images/bullet_black.png +0 -0
  18. data/rdoc/images/bullet_toggle_minus.png +0 -0
  19. data/rdoc/images/bullet_toggle_plus.png +0 -0
  20. data/rdoc/images/date.png +0 -0
  21. data/rdoc/images/delete.png +0 -0
  22. data/rdoc/images/find.png +0 -0
  23. data/rdoc/images/loadingAnimation.gif +0 -0
  24. data/rdoc/images/macFFBgHack.png +0 -0
  25. data/rdoc/images/package.png +0 -0
  26. data/rdoc/images/page_green.png +0 -0
  27. data/rdoc/images/page_white_text.png +0 -0
  28. data/rdoc/images/page_white_width.png +0 -0
  29. data/rdoc/images/plugin.png +0 -0
  30. data/rdoc/images/ruby.png +0 -0
  31. data/rdoc/images/tag_blue.png +0 -0
  32. data/rdoc/images/tag_green.png +0 -0
  33. data/rdoc/images/transparent.png +0 -0
  34. data/rdoc/images/wrench.png +0 -0
  35. data/rdoc/images/wrench_orange.png +0 -0
  36. data/rdoc/images/zoom.png +0 -0
  37. data/rdoc/index.html +83 -21
  38. data/rdoc/js/darkfish.js +153 -0
  39. data/rdoc/js/jquery.js +18 -0
  40. data/rdoc/js/navigation.js +142 -0
  41. data/rdoc/js/search.js +94 -0
  42. data/rdoc/js/search_index.js +1 -0
  43. data/rdoc/js/searcher.js +228 -0
  44. data/rdoc/lib/ofac/models/ofac_rb.html +89 -0
  45. data/rdoc/lib/ofac/models/ofac_sdn_loader_rb.html +89 -0
  46. data/rdoc/lib/ofac/models/ofac_sdn_rb.html +89 -0
  47. data/rdoc/lib/ofac/ofac_match_rb.html +89 -0
  48. data/rdoc/lib/ofac/ruby_string_extensions_rb.html +89 -0
  49. data/rdoc/lib/ofac_rb.html +89 -0
  50. data/rdoc/rdoc.css +543 -0
  51. data/rdoc/table_of_contents.html +94 -0
  52. metadata +52 -19
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.2.4 2012-02-14
2
+
3
+ * 1 enhancements:
4
+ * use a proxy server if the ENV['http_proxy'] variable is set. ie. your.proxy.addr:8080
5
+
1
6
  == 1.2.2, 1.2.3 2011-03-07
2
7
 
3
8
  * 1 enhancement:
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'yaml'
3
4
 
4
5
  begin
5
6
  require 'jeweler'
@@ -43,7 +44,7 @@ end
43
44
 
44
45
  task :default => :test
45
46
 
46
- require 'rake/rdoctask'
47
+ require 'rdoc/task'
47
48
  Rake::RDocTask.new do |rdoc|
48
49
  if File.exist?('VERSION.yml')
49
50
  config = YAML.load(File.read('VERSION.yml'))
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 2
4
- :patch: 3
4
+ :patch: 4
5
5
  :build:
@@ -11,8 +11,13 @@ class OfacSdnLoader
11
11
  puts "Downloading OFAC data from http://www.treas.gov/offices/enforcement/ofac/sdn"
12
12
  yield "Downloading OFAC data from http://www.treas.gov/offices/enforcement/ofac/sdn" if block_given?
13
13
  #get the 3 data files
14
- sdn = Tempfile.new('sdn')
15
- bytes = sdn.write(Net::HTTP.get(URI.parse('http://www.treasury.gov/ofac/downloads/sdn.pip')))
14
+ sdn = Tempfile.new('sdn')
15
+ uri = URI.parse('http://www.treasury.gov/ofac/downloads/sdn.pip')
16
+
17
+ proxy_addr, proxy_port = ENV['http_proxy'].gsub("http://", "").split(/:/) if ENV['http_proxy']
18
+ proxy_user, proxy_pass = uri.userinfo.split(/:/) if uri.userinfo
19
+
20
+ bytes = sdn.write(Net::HTTP::Proxy(proxy_addr, proxy_port, proxy_user, proxy_pass).get(uri))
16
21
  sdn.rewind
17
22
  if bytes == 0 || convert_line_to_array(sdn.readline).size != 12
18
23
  puts "Trouble downloading file. The url may have changed."
@@ -36,11 +41,11 @@ class OfacSdnLoader
36
41
  yield status if block_given?
37
42
  end
38
43
 
39
- bulk_mysql_update(csv_file)do |status|
44
+ bulk_mysql_update(csv_file) do |status|
40
45
  yield status if block_given?
41
46
  end
42
47
  else
43
- active_record_file_load(sdn, address, alt)do |status|
48
+ active_record_file_load(sdn, address, alt) do |status|
44
49
  yield status if block_given?
45
50
  end
46
51
  end
@@ -70,7 +75,7 @@ class OfacSdnLoader
70
75
  #1 array of address records and one array of alt records
71
76
  def self.foreign_key_records(sdn_id)
72
77
  address_records = []
73
- alt_records = []
78
+ alt_records = []
74
79
 
75
80
  #the first element in each array is the primary and foreign keys
76
81
  #we are denormalizing the data
@@ -103,18 +108,18 @@ class OfacSdnLoader
103
108
  def self.sdn_text_to_hash(line)
104
109
  unless line.nil?
105
110
  value_array = convert_line_to_array(line)
106
- {:id => value_array[0],
107
- :name => value_array[1],
108
- :sdn_type => value_array[2],
109
- :program => value_array[3],
110
- :title => value_array[4],
111
- :vessel_call_sign => value_array[5],
112
- :vessel_type => value_array[6],
113
- :vessel_tonnage => value_array[7],
111
+ {:id => value_array[0],
112
+ :name => value_array[1],
113
+ :sdn_type => value_array[2],
114
+ :program => value_array[3],
115
+ :title => value_array[4],
116
+ :vessel_call_sign => value_array[5],
117
+ :vessel_type => value_array[6],
118
+ :vessel_tonnage => value_array[7],
114
119
  :gross_registered_tonnage => value_array[8],
115
- :vessel_flag => value_array[9],
116
- :vessel_owner => value_array[10],
117
- :remarks => value_array[11]
120
+ :vessel_flag => value_array[9],
121
+ :vessel_owner => value_array[10],
122
+ :remarks => value_array[11]
118
123
  }
119
124
  end
120
125
  end
@@ -122,10 +127,10 @@ class OfacSdnLoader
122
127
  def self.address_text_to_hash(line)
123
128
  unless line.nil?
124
129
  value_array = convert_line_to_array(line)
125
- {:id => value_array[0],
126
- :address => value_array[2],
127
- :city => value_array[3],
128
- :country => value_array[4],
130
+ {:id => value_array[0],
131
+ :address => value_array[2],
132
+ :city => value_array[3],
133
+ :country => value_array[4],
129
134
  :address_remarks => value_array[5]
130
135
  }
131
136
  end
@@ -134,9 +139,9 @@ class OfacSdnLoader
134
139
  def self.alt_text_to_hash(line)
135
140
  unless line.nil?
136
141
  value_array = convert_line_to_array(line)
137
- {:id => value_array[0],
138
- :alternate_identity_type => value_array[2],
139
- :alternate_identity_name => value_array[3],
142
+ {:id => value_array[0],
143
+ :alternate_identity_type => value_array[2],
144
+ :alternate_identity_name => value_array[3],
140
145
  :alternate_identity_remarks => value_array[4]
141
146
  }
142
147
  end
@@ -146,67 +151,67 @@ class OfacSdnLoader
146
151
  # empty field for id to be generated by mysql.
147
152
  new_line = "``|" +
148
153
  # :name
149
- "`#{record_hash[:name]}`|" +
154
+ "`#{record_hash[:name]}`|" +
150
155
  # :sdn_type
151
- "`#{record_hash[:sdn_type]}`|" +
156
+ "`#{record_hash[:sdn_type]}`|" +
152
157
  # :program
153
- "`#{record_hash[:program]}`|" +
158
+ "`#{record_hash[:program]}`|" +
154
159
  # :title
155
- "`#{record_hash[:title]}`|" +
160
+ "`#{record_hash[:title]}`|" +
156
161
  # :vessel_call_sign
157
- "`#{record_hash[:vessel_call_sign]}`|" +
162
+ "`#{record_hash[:vessel_call_sign]}`|" +
158
163
  # :vessel_type
159
- "`#{record_hash[:vessel_type]}`|" +
164
+ "`#{record_hash[:vessel_type]}`|" +
160
165
  # :vessel_tonnage
161
- "`#{record_hash[:vessel_tonnage]}`|" +
166
+ "`#{record_hash[:vessel_tonnage]}`|" +
162
167
  # :gross_registered_tonnage
163
- "`#{record_hash[:gross_registered_tonnage]}`|" +
168
+ "`#{record_hash[:gross_registered_tonnage]}`|" +
164
169
  # :vessel_flag
165
- "`#{record_hash[:vessel_flag]}`|" +
170
+ "`#{record_hash[:vessel_flag]}`|" +
166
171
  # :vessel_owner
167
- "`#{record_hash[:vessel_owner]}`|" +
172
+ "`#{record_hash[:vessel_owner]}`|" +
168
173
  # :remarks
169
- "`#{record_hash[:remarks]}`|" +
174
+ "`#{record_hash[:remarks]}`|" +
170
175
  # :address
171
- "`#{record_hash[:address]}`|" +
176
+ "`#{record_hash[:address]}`|" +
172
177
  # :city
173
- "`#{record_hash[:city]}`|" +
178
+ "`#{record_hash[:city]}`|" +
174
179
  # :country
175
- "`#{record_hash[:country]}`|" +
180
+ "`#{record_hash[:country]}`|" +
176
181
  # :address_remarks
177
- "`#{record_hash[:address_remarks]}`|" +
182
+ "`#{record_hash[:address_remarks]}`|" +
178
183
  # :alternate_identity_type
179
- "`#{record_hash[:alternate_identity_type]}`|" +
184
+ "`#{record_hash[:alternate_identity_type]}`|" +
180
185
  # :alternate_identity_name
181
- "`#{record_hash[:alternate_identity_name]}`|" +
186
+ "`#{record_hash[:alternate_identity_name]}`|" +
182
187
  # :alternate_identity_remarks
183
- "`#{record_hash[:alternate_identity_remarks]}`|" +
188
+ "`#{record_hash[:alternate_identity_remarks]}`|" +
184
189
  #:created_at
185
- "`#{Time.now.to_s(:db)}`|" +
190
+ "`#{Time.now.to_s(:db)}`|" +
186
191
  # updated_at
187
- "`#{Time.now.to_s(:db)}`" + "\n"
192
+ "`#{Time.now.to_s(:db)}`" + "\n"
188
193
 
189
194
  new_line
190
195
  end
191
196
 
192
197
  def self.convert_to_flattened_csv(sdn_file, address_file, alt_file)
193
- @address = address_file
194
- @alt = alt_file
198
+ @address = address_file
199
+ @alt = alt_file
195
200
 
196
- csv_file = Tempfile.new("ofac") # create temp file for converted csv format.
197
- #get the first line from the address and alt files
201
+ csv_file = Tempfile.new("ofac") # create temp file for converted csv format.
202
+ #get the first line from the address and alt files
198
203
  @current_address_hash = address_text_to_hash(@address.gets)
199
- @current_alt_hash = alt_text_to_hash(@alt.gets)
204
+ @current_alt_hash = alt_text_to_hash(@alt.gets)
200
205
 
201
- start = Time.now
206
+ start = Time.now
202
207
 
203
208
  sdn_file.each_with_index do |line, i|
204
209
 
205
210
  #initialize the address and alt atributes to empty strings
206
211
  address_attributes = address_text_to_hash("|||||")
207
- alt_attributes = alt_text_to_hash("||||")
212
+ alt_attributes = alt_text_to_hash("||||")
208
213
 
209
- sdn_attributes = sdn_text_to_hash(line)
214
+ sdn_attributes = sdn_text_to_hash(line)
210
215
 
211
216
  #get the foreign key records for this sdn
212
217
  address_records, alt_records = foreign_key_records(sdn_attributes[:id])
@@ -245,22 +250,22 @@ class OfacSdnLoader
245
250
 
246
251
  def self.active_record_file_load(sdn_file, address_file, alt_file)
247
252
  @address = address_file
248
- @alt = alt_file
253
+ @alt = alt_file
249
254
 
250
255
  #OFAC data is a complete list, so we have to dump and load
251
256
  OfacSdn.delete_all
252
257
 
253
258
  #get the first line from the address and alt files
254
259
  @current_address_hash = address_text_to_hash(@address.gets)
255
- @current_alt_hash = alt_text_to_hash(@alt.gets)
256
- attributes = {}
260
+ @current_alt_hash = alt_text_to_hash(@alt.gets)
261
+ attributes = {}
257
262
  sdn_file.each_with_index do |line, i|
258
263
 
259
264
  #initialize the address and alt atributes to empty strings
260
265
  address_attributes = address_text_to_hash("|||||")
261
- alt_attributes = alt_text_to_hash("||||")
266
+ alt_attributes = alt_text_to_hash("||||")
262
267
 
263
- sdn_attributes = sdn_text_to_hash(line)
268
+ sdn_attributes = sdn_text_to_hash(line)
264
269
 
265
270
  #get the foreign key records for this sdn
266
271
  address_records, alt_records = foreign_key_records(sdn_attributes[:id])
data/ofac.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ofac}
8
- s.version = "1.2.3"
8
+ s.version = "1.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Kevin Tyll"]
12
- s.date = %q{2011-03-07}
11
+ s.authors = [%q{Kevin Tyll}]
12
+ s.date = %q{2012-02-14}
13
13
  s.description = %q{Attempts to find a hit on the Office of Foreign Assets Control's Specially Designated Nationals list.}
14
14
  s.email = %q{kevintyll@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -40,6 +40,12 @@ Gem::Specification.new do |s|
40
40
  "ofac.gemspec",
41
41
  "pkg/ofac-0.1.0.gem",
42
42
  "pkg/ofac-1.0.0.gem",
43
+ "rdoc/Ofac.html",
44
+ "rdoc/OfacMatch.html",
45
+ "rdoc/OfacSdn.html",
46
+ "rdoc/OfacSdnLoader.html",
47
+ "rdoc/README_rdoc.html",
48
+ "rdoc/String.html",
43
49
  "rdoc/classes/Ofac.html",
44
50
  "rdoc/classes/OfacMatch.html",
45
51
  "rdoc/classes/OfacSdn.html",
@@ -56,8 +62,46 @@ Gem::Specification.new do |s|
56
62
  "rdoc/fr_class_index.html",
57
63
  "rdoc/fr_file_index.html",
58
64
  "rdoc/fr_method_index.html",
65
+ "rdoc/images/add.png",
66
+ "rdoc/images/brick.png",
67
+ "rdoc/images/brick_link.png",
68
+ "rdoc/images/bug.png",
69
+ "rdoc/images/bullet_black.png",
70
+ "rdoc/images/bullet_toggle_minus.png",
71
+ "rdoc/images/bullet_toggle_plus.png",
72
+ "rdoc/images/date.png",
73
+ "rdoc/images/delete.png",
74
+ "rdoc/images/find.png",
75
+ "rdoc/images/loadingAnimation.gif",
76
+ "rdoc/images/macFFBgHack.png",
77
+ "rdoc/images/package.png",
78
+ "rdoc/images/page_green.png",
79
+ "rdoc/images/page_white_text.png",
80
+ "rdoc/images/page_white_width.png",
81
+ "rdoc/images/plugin.png",
82
+ "rdoc/images/ruby.png",
83
+ "rdoc/images/tag_blue.png",
84
+ "rdoc/images/tag_green.png",
85
+ "rdoc/images/transparent.png",
86
+ "rdoc/images/wrench.png",
87
+ "rdoc/images/wrench_orange.png",
88
+ "rdoc/images/zoom.png",
59
89
  "rdoc/index.html",
90
+ "rdoc/js/darkfish.js",
91
+ "rdoc/js/jquery.js",
92
+ "rdoc/js/navigation.js",
93
+ "rdoc/js/search.js",
94
+ "rdoc/js/search_index.js",
95
+ "rdoc/js/searcher.js",
96
+ "rdoc/lib/ofac/models/ofac_rb.html",
97
+ "rdoc/lib/ofac/models/ofac_sdn_loader_rb.html",
98
+ "rdoc/lib/ofac/models/ofac_sdn_rb.html",
99
+ "rdoc/lib/ofac/ofac_match_rb.html",
100
+ "rdoc/lib/ofac/ruby_string_extensions_rb.html",
101
+ "rdoc/lib/ofac_rb.html",
60
102
  "rdoc/rdoc-style.css",
103
+ "rdoc/rdoc.css",
104
+ "rdoc/table_of_contents.html",
61
105
  "test/files/test_address_data_load.pip",
62
106
  "test/files/test_alt_data_load.pip",
63
107
  "test/files/test_sdn_data_load.pip",
@@ -79,21 +123,14 @@ Gem::Specification.new do |s|
79
123
 
80
124
  * The OFAC data is not updated with any regularity, but you can sign up for email notifications when the data changes at
81
125
  http://www.treas.gov/offices/enforcement/ofac/sdn/index.shtml.}
82
- s.require_paths = ["lib"]
83
- s.rubygems_version = %q{1.3.6}
126
+ s.require_paths = [%q{lib}]
127
+ s.rubygems_version = %q{1.8.9}
84
128
  s.summary = %q{Attempts to find a hit on the Office of Foreign Assets Control's Specially Designated Nationals list.}
85
- s.test_files = [
86
- "test/mocks/test/ofac_sdn_loader.rb",
87
- "test/ofac_sdn_loader_test.rb",
88
- "test/ofac_test.rb",
89
- "test/test_helper.rb"
90
- ]
91
129
 
92
130
  if s.respond_to? :specification_version then
93
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
94
131
  s.specification_version = 3
95
132
 
96
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
133
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
97
134
  else
98
135
  end
99
136
  else
data/rdoc/Ofac.html ADDED
@@ -0,0 +1,423 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>Class: Ofac</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="class">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="./index.html">Home</a>
28
+ <a href="./table_of_contents.html#classes">Classes</a>
29
+ <a href="./table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/ofac/models/ofac.rb
51
+ </ul>
52
+ </nav>
53
+
54
+
55
+ </div>
56
+
57
+ <div id="class-metadata">
58
+
59
+ <nav id="parent-class-section" class="section">
60
+ <h3 class="section-header">Parent</h3>
61
+
62
+ <p class="link">Object
63
+
64
+ </nav>
65
+
66
+
67
+ <!-- Method Quickref -->
68
+ <nav id="method-list-section" class="section">
69
+ <h3 class="section-header">Methods</h3>
70
+
71
+ <ul class="link-list">
72
+
73
+ <li><a href="#method-c-new">::new</a>
74
+
75
+ <li><a href="#method-i-db_hit-3F">#db_hit?</a>
76
+
77
+ <li><a href="#method-i-possible_hits">#possible_hits</a>
78
+
79
+ <li><a href="#method-i-score">#score</a>
80
+
81
+ </ul>
82
+ </nav>
83
+
84
+ </div>
85
+
86
+ <div id="project-metadata">
87
+ <nav id="fileindex-section" class="section project-section">
88
+ <h3 class="section-header">Pages</h3>
89
+
90
+ <ul>
91
+
92
+ <li class="file"><a href="./README_rdoc.html">README</a>
93
+
94
+ </ul>
95
+ </nav>
96
+
97
+ <nav id="classindex-section" class="section project-section">
98
+ <h3 class="section-header">Class and Module Index</h3>
99
+
100
+ <ul class="link-list">
101
+
102
+ <li><a href="./Ofac.html">Ofac</a>
103
+
104
+ <li><a href="./OfacMatch.html">OfacMatch</a>
105
+
106
+ <li><a href="./OfacSdn.html">OfacSdn</a>
107
+
108
+ <li><a href="./OfacSdnLoader.html">OfacSdnLoader</a>
109
+
110
+ <li><a href="./String.html">String</a>
111
+
112
+ </ul>
113
+ </nav>
114
+
115
+ </div>
116
+ </nav>
117
+
118
+ <div id="documentation">
119
+ <h1 class="class">class Ofac</h1>
120
+
121
+ <div id="description" class="description">
122
+
123
+ </div><!-- description -->
124
+
125
+
126
+
127
+
128
+ <section id="5Buntitled-5D" class="documentation-section">
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+ <!-- Methods -->
138
+
139
+ <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
140
+ <h3 class="section-header">Public Class Methods</h3>
141
+
142
+
143
+ <div id="method-c-new" class="method-detail ">
144
+
145
+ <div class="method-heading">
146
+ <span class="method-name">new</span><span
147
+ class="method-args">(identity)</span>
148
+ <span class="method-click-advice">click to toggle source</span>
149
+ </div>
150
+
151
+
152
+ <div class="method-description">
153
+
154
+ <p>Accepts a hash with the identity’s demographic information</p>
155
+
156
+ <pre class="ruby"><span class="ruby-constant">Ofac</span>.<span class="ruby-identifier">new</span>({:<span class="ruby-identifier">name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'Oscar Hernandez'</span>, :<span class="ruby-identifier">city</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'Clearwater'</span>, :<span class="ruby-identifier">address</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'123 somewhere ln'</span>})
157
+ </pre>
158
+
159
+ <p><code>:name</code> is required to get a score. If <code>:name</code> is
160
+ missing, an error will not be thrown, but a score of 0 will be returned.</p>
161
+
162
+ <p>You can pass a string in for the full name:</p>
163
+
164
+ <pre class="ruby"><span class="ruby-constant">Ofac</span>.<span class="ruby-identifier">new</span>(:<span class="ruby-identifier">name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'Victor De La Garza'</span>)
165
+ </pre>
166
+
167
+ <p>Or you can specify the last and first names</p>
168
+
169
+ <pre class="ruby"><span class="ruby-constant">Ofac</span>.<span class="ruby-identifier">new</span>(:<span class="ruby-identifier">name</span> =<span class="ruby-operator">&gt;</span> {:<span class="ruby-identifier">first_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'Victor'</span>, :<span class="ruby-identifier">last_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'De La Garza'</span>})
170
+ </pre>
171
+
172
+ <p>The first method will build a larger list of names for ruby to parse
173
+ through and more likely to find similar names. The second method is
174
+ quicker.</p>
175
+
176
+ <p>The more information provided, the higher the score could be. A score of
177
+ 100 would mean all fields were passed in, and all fields were 100% matches.
178
+ If only the name is passed in without an address, it will be impossible to
179
+ get a score of 100, even if the name matches perfectly.</p>
180
+
181
+ <p>Acceptable hash keys and their weighting in score calculation:</p>
182
+ <ul><li>
183
+ <p><code>:name</code> (weighting = 60%) (required) This can be a person,
184
+ business, or marine vessel</p>
185
+ </li><li>
186
+ <p><code>:address</code> (weighting = 10%)</p>
187
+ </li><li>
188
+ <p><code>:city</code> (weighting = 30%)</p>
189
+ </li></ul>
190
+
191
+
192
+
193
+ <div class="method-source-code" id="new-source">
194
+ <pre><span class="ruby-comment"># File lib/ofac/models/ofac.rb, line 28</span>
195
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">identity</span>)
196
+ <span class="ruby-ivar">@identity</span> = <span class="ruby-identifier">identity</span>
197
+ <span class="ruby-keyword">end</span></pre>
198
+ </div><!-- new-source -->
199
+
200
+ </div>
201
+
202
+
203
+
204
+
205
+ </div><!-- new-method -->
206
+
207
+
208
+ </section><!-- public-class-method-details -->
209
+
210
+ <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
211
+ <h3 class="section-header">Public Instance Methods</h3>
212
+
213
+
214
+ <div id="method-i-db_hit-3F" class="method-detail ">
215
+
216
+ <div class="method-heading">
217
+ <span class="method-name">db_hit?</span><span
218
+ class="method-args">()</span>
219
+ <span class="method-click-advice">click to toggle source</span>
220
+ </div>
221
+
222
+
223
+ <div class="method-description">
224
+
225
+
226
+
227
+
228
+
229
+ <div class="method-source-code" id="db_hit-3F-source">
230
+ <pre><span class="ruby-comment"># File lib/ofac/models/ofac.rb, line 89</span>
231
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">db_hit?</span>
232
+ <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@identity</span>[<span class="ruby-value">:name</span>].<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">blank?</span>
233
+
234
+ <span class="ruby-comment">#first get a list from the database of possible matches by name</span>
235
+ <span class="ruby-comment">#this query is pretty liberal, we just want to get a list of possible</span>
236
+ <span class="ruby-comment">#matches from the database that we can run through our ruby matching algorithm</span>
237
+ <span class="ruby-identifier">possible_sdns</span> = []
238
+ <span class="ruby-identifier">name_array</span> = <span class="ruby-identifier">process_name</span>
239
+
240
+ <span class="ruby-identifier">name_array</span>.<span class="ruby-identifier">delete_if</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">2</span>}
241
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">name_array</span>.<span class="ruby-identifier">empty?</span>
242
+ <span class="ruby-identifier">sql_name_partial</span> = <span class="ruby-identifier">name_array</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">partial_name</span><span class="ruby-operator">|</span> [<span class="ruby-string">&quot;name like ?&quot;</span>, <span class="ruby-node">&quot;%#{partial_name}%&quot;</span>]}
243
+ <span class="ruby-identifier">sql_alt_name_partial</span> = <span class="ruby-identifier">name_array</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">partial_name</span><span class="ruby-operator">|</span> [<span class="ruby-string">&quot;alternate_identity_name like ?&quot;</span>, <span class="ruby-node">&quot;%#{partial_name}%&quot;</span>]}
244
+
245
+ <span class="ruby-identifier">name_conditions</span> = <span class="ruby-identifier">sql_name_partial</span>.<span class="ruby-identifier">transpose</span>
246
+ <span class="ruby-identifier">name_values</span> = <span class="ruby-identifier">name_conditions</span>.<span class="ruby-identifier">second</span>
247
+ <span class="ruby-identifier">name_conditions</span> = [<span class="ruby-identifier">name_conditions</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">' and '</span>)]
248
+ <span class="ruby-identifier">alt_name_conditions</span> = <span class="ruby-identifier">sql_alt_name_partial</span>.<span class="ruby-identifier">transpose</span>
249
+ <span class="ruby-identifier">alt_name_values</span> = <span class="ruby-identifier">alt_name_conditions</span>.<span class="ruby-identifier">second</span>
250
+ <span class="ruby-identifier">alt_name_conditions</span> = [<span class="ruby-identifier">alt_name_conditions</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">' and '</span>)]
251
+ <span class="ruby-identifier">conditions</span> = [<span class="ruby-node">&quot;(#{name_conditions}) or (#{alt_name_conditions})&quot;</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">name_values</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">alt_name_values</span>
252
+
253
+ <span class="ruby-identifier">possible_sdns</span> = <span class="ruby-constant">OfacSdn</span>.<span class="ruby-identifier">find_all_by_sdn_type</span>(<span class="ruby-string">'individual'</span>,<span class="ruby-value">:select</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'name, alternate_identity_name, address, city'</span>, <span class="ruby-value">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conditions</span>)
254
+
255
+ <span class="ruby-keyword">end</span>
256
+ <span class="ruby-keyword">end</span>
257
+ <span class="ruby-operator">!</span><span class="ruby-identifier">possible_sdns</span>.<span class="ruby-identifier">empty?</span>
258
+ <span class="ruby-keyword">end</span></pre>
259
+ </div><!-- db_hit-3F-source -->
260
+
261
+ </div>
262
+
263
+
264
+
265
+
266
+ </div><!-- db_hit-3F-method -->
267
+
268
+
269
+ <div id="method-i-possible_hits" class="method-detail ">
270
+
271
+ <div class="method-heading">
272
+ <span class="method-name">possible_hits</span><span
273
+ class="method-args">()</span>
274
+ <span class="method-click-advice">click to toggle source</span>
275
+ </div>
276
+
277
+
278
+ <div class="method-description">
279
+
280
+ <pre class="ruby"><span class="ruby-constant">Returns</span> <span class="ruby-identifier">an</span> <span class="ruby-identifier">array</span> <span class="ruby-identifier">of</span> <span class="ruby-identifier">hashes</span> <span class="ruby-identifier">of</span> <span class="ruby-identifier">records</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">the</span> <span class="ruby-constant">OFAC</span> <span class="ruby-identifier">data</span> <span class="ruby-identifier">that</span> <span class="ruby-identifier">found</span> <span class="ruby-identifier">partial</span> <span class="ruby-identifier">matches</span> <span class="ruby-identifier">with</span> <span class="ruby-identifier">that</span> <span class="ruby-identifier">record</span><span class="ruby-string">'s score.
281
+
282
+ Ofac.new({:name =&gt; '</span><span class="ruby-constant">Oscar</span> <span class="ruby-constant">Hernandez</span><span class="ruby-string">', :city =&gt; '</span><span class="ruby-constant">Clearwater</span><span class="ruby-string">', :address =&gt; '</span><span class="ruby-value">123</span> <span class="ruby-identifier">somewhere</span> <span class="ruby-identifier">ln</span><span class="ruby-string">'}).possible_hits
283
+ </span></pre>
284
+
285
+ <p>returns</p>
286
+
287
+ <pre class="ruby">[{:<span class="ruby-identifier">address=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">&quot;123 Somewhere Ln&quot;</span>, :<span class="ruby-identifier">score=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">100</span>, :<span class="ruby-identifier">name=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">&quot;HERNANDEZ, Oscar|GUAMATUR, S.A.&quot;</span>, :<span class="ruby-identifier">city=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">&quot;Clearwater&quot;</span>}, {:<span class="ruby-identifier">address=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">&quot;123 Somewhere Ln&quot;</span>, :<span class="ruby-identifier">score=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">100</span>, :<span class="ruby-identifier">name=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">&quot;HERNANDEZ, Oscar|Alternate Name&quot;</span>, :<span class="ruby-identifier">city=</span><span class="ruby-operator">&gt;</span><span class="ruby-string">&quot;Clearwater&quot;</span>}]
288
+ </pre>
289
+
290
+
291
+
292
+ <div class="method-source-code" id="possible_hits-source">
293
+ <pre><span class="ruby-comment"># File lib/ofac/models/ofac.rb, line 124</span>
294
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">possible_hits</span>
295
+ <span class="ruby-ivar">@possible_hits</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">retrieve_possible_hits</span>
296
+ <span class="ruby-keyword">end</span></pre>
297
+ </div><!-- possible_hits-source -->
298
+
299
+ </div>
300
+
301
+
302
+
303
+
304
+ </div><!-- possible_hits-method -->
305
+
306
+
307
+ <div id="method-i-score" class="method-detail ">
308
+
309
+ <div class="method-heading">
310
+ <span class="method-name">score</span><span
311
+ class="method-args">()</span>
312
+ <span class="method-click-advice">click to toggle source</span>
313
+ </div>
314
+
315
+
316
+ <div class="method-description">
317
+
318
+ <p>Creates a score, 1 - 100, based on how well the name and address match the
319
+ data on the SDN (Specially Designated Nationals) list.</p>
320
+
321
+ <p>The score is calculated by adding up the weightings of each part that is
322
+ matched. So if only name is matched, then the max score is the weight for
323
+ <code>:name</code> which is 60</p>
324
+
325
+ <p>It’s possible to get partial matches, which will add partial weight to
326
+ the score. If there is not a match on the element as it is passed in, then
327
+ each word element gets broken down and matches are tried on each partial
328
+ element. The weighting is distrubuted equally for each partial that is
329
+ matched.</p>
330
+
331
+ <p>If exact matches are not made, then a sounds like match is attempted. Any
332
+ match made by sounds like is given 75% of it’s weight to the score.</p>
333
+
334
+ <p>Example:</p>
335
+
336
+ <p>If you are trying to match the name Kevin Tyll and there is a record for
337
+ Smith, Kevin in the database, then we will try to match both Kevin and Tyll
338
+ separately, with each element Smith and Kevin. Since only Kevin will find
339
+ a match, and there were 2 elements in the searched name, the score will be
340
+ added by half the weighting for <code>:name</code>. So since the weight
341
+ for <code>:name</code> is 60, then we will add 30 to the score.</p>
342
+
343
+ <p>If you are trying to match the name Kevin Gregory Tyll and there is a
344
+ record for Tyll, Kevin in the database, then we will try to match Kevin and
345
+ Gregory and Tyll separately, with each element Tyll and Kevin. Since both
346
+ Kevin and Tyll will find a match, and there were 3 elements in the searched
347
+ name, the score will be added by 2/3 the weighting for <code>:name</code>.
348
+ So since the weight for <code>:name</code> is 60, then we will add 40 to
349
+ the score.</p>
350
+
351
+ <p>If you are trying to match the name Kevin Tyll and there is a record for
352
+ Kevin Gregory Tyll in the database, then we will try to match Kevin and
353
+ Tyll separately, with each element Tyll and Kevin and Gregory. Since both
354
+ Kevin and Tyll will find a match, and there were 2 elements in the searched
355
+ name, the score will be added by 2/2 the weighting for <code>:name</code>.
356
+ So since the weight for <code>:name</code> is 60, then we will add 60 to
357
+ the score.</p>
358
+
359
+ <p>If you are trying to match the name Kevin Tyll, and there is a record for
360
+ Teel, Kevin in the database, then an exact match will be found for Kevin,
361
+ and a sounds like match will be made for Tyll. Since there were 2 elements
362
+ in the searched name, and the weight for <code>:name</code> is 60, then
363
+ each element is worth 30. Since Kevin was an exact match, it will add 30,
364
+ and since Tyll was a sounds like match, it will add 30 * .75. So the
365
+ <code>:name</code> portion of the search will be worth 53.</p>
366
+
367
+ <p>If data is in the database for city and or address, and you pass data in
368
+ for these elements, the score will be reduced by 10% of the weight if there
369
+ is no match or sounds like match. So if you get a match on name, you’ve
370
+ already got a score of 60. So if you don’t pass in an address or city,
371
+ or if you do, but there is no city or address info in the database, then
372
+ your final score will be 60. But if you do pass in a city, say Tampa, and
373
+ the city in the Database is New York, then we will deduct 10% of the weight
374
+ (30 * .1) = 3 from the score since 30 is the weight for <code>:city</code>.
375
+ So the final score will be 57.</p>
376
+
377
+ <p>If were searching for New York, and the database had New Deli, then there
378
+ would be a match on New, but not on Deli. Since there were 2 elements in
379
+ the searched city, each hit is worth 15. So the match on New would add 15,
380
+ but the non-match on York would subtract (15 * .1) = 1.5 from the score.
381
+ So the score would be (60 + 15 - 1.5) = 74, due to rounding.</p>
382
+
383
+ <p>Only <code>:city</code> and <code>:address</code> subtract from the score,
384
+ No match on name simply returns 0.</p>
385
+
386
+ <p>Matches for name are made for both the name and any aliases in the OFAC
387
+ database.</p>
388
+
389
+ <p>Matches for <code>:city</code> and <code>:address</code> will only be added
390
+ to the score if there is first a match on <code>:name</code>.</p>
391
+
392
+ <p>We consider a score of 60 to be reasonable as a hit.</p>
393
+
394
+
395
+
396
+ <div class="method-source-code" id="score-source">
397
+ <pre><span class="ruby-comment"># File lib/ofac/models/ofac.rb, line 85</span>
398
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">score</span>
399
+ <span class="ruby-ivar">@score</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">calculate_score</span>
400
+ <span class="ruby-keyword">end</span></pre>
401
+ </div><!-- score-source -->
402
+
403
+ </div>
404
+
405
+
406
+
407
+
408
+ </div><!-- score-method -->
409
+
410
+
411
+ </section><!-- public-instance-method-details -->
412
+
413
+ </section><!-- 5Buntitled-5D -->
414
+
415
+ </div><!-- documentation -->
416
+
417
+
418
+ <footer id="validator-badges">
419
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
420
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
421
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
422
+ </footer>
423
+