ssn_validator 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/VERSION.yml +1 -1
- data/lib/ssn_validator/models/death_master_file_loader.rb +81 -68
- data/lib/ssn_validator/models/ssn_high_group_code_loader.rb +5 -1
- data/rdoc/classes/DeathMasterFileLoader.html +28 -22
- data/rdoc/classes/SsnHighGroupCodeLoader.html +5 -3
- data/rdoc/created.rid +1 -1
- data/rdoc/files/lib/ssn_validator/models/death_master_file_loader_rb.html +1 -1
- data/rdoc/files/lib/ssn_validator/models/ssn_high_group_code_loader_rb.html +1 -1
- data/rdoc/index.html +2 -2
- data/ssn_validator.gemspec +2 -2
- metadata +3 -3
data/History.txt
CHANGED
data/VERSION.yml
CHANGED
@@ -8,10 +8,10 @@ class DeathMasterFileLoader
|
|
8
8
|
|
9
9
|
# path_or_url is the full path to the file to load on disk, or the url of an update file.
|
10
10
|
# as_of is a string in the formatt YYYY-MM-DD for which the file data is accurate.
|
11
|
-
def initialize(path_or_url,file_as_of)
|
11
|
+
def initialize(path_or_url, file_as_of)
|
12
12
|
@file_path_or_url = path_or_url
|
13
|
-
@file_as_of
|
14
|
-
valid?
|
13
|
+
@file_as_of = file_as_of
|
14
|
+
valid?{|status| yield status if block_given?}
|
15
15
|
end
|
16
16
|
|
17
17
|
def valid?
|
@@ -23,7 +23,7 @@ class DeathMasterFileLoader
|
|
23
23
|
if File.exists?(@file_path_or_url)
|
24
24
|
@download_file = File.open(@file_path_or_url)
|
25
25
|
elsif URI.parse(@file_path_or_url).kind_of?(URI::HTTP)
|
26
|
-
@download_file = File.open(get_file_from_web)
|
26
|
+
@download_file = File.open(get_file_from_web{|status| yield status if block_given?})
|
27
27
|
else
|
28
28
|
raise(Errno::ENOENT, @file_path_or_url)
|
29
29
|
end
|
@@ -33,27 +33,28 @@ class DeathMasterFileLoader
|
|
33
33
|
|
34
34
|
if DeathMasterFile.connection.kind_of?(ActiveRecord::ConnectionAdapters::MysqlAdapter) || DeathMasterFile.connection.kind_of?(ActiveRecord::ConnectionAdapters::JdbcAdapter)
|
35
35
|
puts "Converting file to csv format for Mysql import. This could take several minutes."
|
36
|
+
yield "Converting file to csv format for Mysql import. This could take several minutes." if block_given?
|
36
37
|
|
37
|
-
csv_file = convert_file_to_csv
|
38
|
+
csv_file = convert_file_to_csv{|status| yield status if block_given?}
|
38
39
|
|
39
|
-
bulk_mysql_update(csv_file)
|
40
|
+
bulk_mysql_update(csv_file){|status| yield status if block_given?}
|
40
41
|
else
|
41
|
-
active_record_file_load
|
42
|
+
active_record_file_load{|status| yield status if block_given?}
|
42
43
|
end
|
43
44
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def get_file_from_web
|
47
|
-
uri
|
48
|
+
uri = URI.parse(@file_path_or_url)
|
48
49
|
|
49
50
|
request = Net::HTTP::Get.new(uri.request_uri)
|
50
|
-
request.basic_auth(SsnValidator::Ntis.user_name,SsnValidator::Ntis.password)
|
51
|
+
request.basic_auth(SsnValidator::Ntis.user_name, SsnValidator::Ntis.password)
|
51
52
|
|
52
|
-
http
|
53
|
-
http.use_ssl
|
53
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
54
|
+
http.use_ssl = (uri.port == 443)
|
54
55
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
55
56
|
|
56
|
-
csv_file
|
57
|
+
csv_file = Tempfile.new(@file_path_or_url.split('/').last) # create temp file for the raw file.
|
57
58
|
http.request(request) do |res|
|
58
59
|
raise(ArgumentError, "Invalid URL: #{@file_path_or_url}") if res.kind_of?(Net::HTTPNotFound)
|
59
60
|
raise(ArgumentError, "Authorization Required: Invalid username or password. Set the variables SsnValidator::Ntis.user_name and SsnValidator::Ntis.password in your environment.rb file.") if res.kind_of?(Net::HTTPUnauthorized)
|
@@ -62,6 +63,7 @@ class DeathMasterFileLoader
|
|
62
63
|
size += chunk.size
|
63
64
|
csv_file.write chunk
|
64
65
|
puts "%d%% done (%d of %d)" % [(size * 100) / total, size, total]
|
66
|
+
yield("%d%% done (%d of %d)" % [(size * 100) / total, size, total]) if block_given?
|
65
67
|
end
|
66
68
|
|
67
69
|
end
|
@@ -73,13 +75,17 @@ class DeathMasterFileLoader
|
|
73
75
|
#It starts with the last file loaded, and loads each
|
74
76
|
#missing file in sequence up to the current file.
|
75
77
|
def self.load_update_files_from_web
|
76
|
-
max_as_of
|
77
|
-
run_file_date
|
78
|
+
max_as_of = DeathMasterFile.maximum(:as_of)
|
79
|
+
run_file_date = max_as_of.beginning_of_month.next_month
|
78
80
|
last_file_date = Date.today.beginning_of_month
|
79
81
|
while run_file_date <= last_file_date
|
80
82
|
url = "https://dmf.ntis.gov/dmldata/monthly/MA#{run_file_date.strftime("%y%m%d")}"
|
81
83
|
puts "Loading file #{url}"
|
82
|
-
|
84
|
+
yield "Loading file #{url}" if block_given?
|
85
|
+
dmf = DeathMasterFileLoader.new(url, run_file_date.strftime("%Y-%m-%d")){|status| yield status if block_given?}
|
86
|
+
dmf.load_file do |status|
|
87
|
+
yield status if block_given?
|
88
|
+
end
|
83
89
|
run_file_date += 1.month
|
84
90
|
end
|
85
91
|
end
|
@@ -90,16 +96,16 @@ class DeathMasterFileLoader
|
|
90
96
|
# Used to convert a packed fixed-length file into csv for mysql import.
|
91
97
|
def convert_file_to_csv
|
92
98
|
|
93
|
-
csv_file
|
99
|
+
csv_file = Tempfile.new("dmf") # create temp file for converted csv formmat.
|
94
100
|
|
95
101
|
|
96
|
-
start
|
97
|
-
timenow
|
102
|
+
start = Time.now
|
103
|
+
timenow = start.to_s(:db)
|
98
104
|
|
99
105
|
@delete_ssns = []
|
100
|
-
|
101
|
-
@download_file.each_with_index do |line,i|
|
102
|
-
action
|
106
|
+
|
107
|
+
@download_file.each_with_index do |line, i|
|
108
|
+
action = record_action(line)
|
103
109
|
attributes_hash = text_to_hash(line)
|
104
110
|
if action == 'D'
|
105
111
|
#keep track of all the records to delete. We'll delete at the end all at once.
|
@@ -107,40 +113,44 @@ class DeathMasterFileLoader
|
|
107
113
|
else
|
108
114
|
# empty field for id to be generated by mysql.
|
109
115
|
newline = "``," +
|
110
|
-
|
116
|
+
# social_security_number
|
111
117
|
"`#{attributes_hash[:social_security_number]}`," +
|
112
|
-
|
118
|
+
# last_name
|
113
119
|
"`#{attributes_hash[:last_name]}`," +
|
114
|
-
|
120
|
+
# name_suffix
|
115
121
|
"`#{attributes_hash[:name_suffix]}`," +
|
116
|
-
|
122
|
+
# first_name
|
117
123
|
"`#{attributes_hash[:first_name]}`," +
|
118
|
-
|
124
|
+
# middle_name
|
119
125
|
"`#{attributes_hash[:middle_name]}`," +
|
120
|
-
|
126
|
+
# verify_proof_code
|
121
127
|
"`#{attributes_hash[:verify_proof_code]}`," +
|
122
|
-
|
128
|
+
# date_of_death - need YYYY-MM-DD.
|
123
129
|
"`#{attributes_hash[:date_of_death]}`," +
|
124
|
-
|
130
|
+
# date_of_birth - need YYYY-MM-DD.
|
125
131
|
"`#{attributes_hash[:date_of_birth]}`," +
|
126
|
-
|
132
|
+
# state_of_residence - must be code between 01 and 65 or else nil.
|
127
133
|
"`#{attributes_hash[:state_of_residence]}`," +
|
128
|
-
|
134
|
+
# last_known_zip_residence
|
129
135
|
"`#{attributes_hash[:last_known_zip_residence]}`," +
|
130
|
-
|
136
|
+
# last_known_zip_payment
|
131
137
|
"`#{attributes_hash[:last_known_zip_payment]}`," +
|
132
|
-
|
138
|
+
# created_at
|
133
139
|
"`#{timenow}`," +
|
134
|
-
|
140
|
+
# updated_at
|
135
141
|
"`#{timenow}`," +
|
136
|
-
|
142
|
+
# as_of
|
137
143
|
"`#{attributes_hash[:as_of]}`" +"\n"
|
138
144
|
|
139
145
|
csv_file.syswrite newline
|
140
|
-
|
146
|
+
if (i % 25000 == 0) && (i > 0)
|
147
|
+
puts "#{i} records processed."
|
148
|
+
yield "#{i} records processed." if block_given?
|
149
|
+
end
|
141
150
|
end
|
142
151
|
end
|
143
152
|
puts "File conversion ran for #{(Time.now - start) / 60} minutes."
|
153
|
+
yield "File conversion ran for #{(Time.now - start) / 60} minutes." if block_given?
|
144
154
|
return csv_file
|
145
155
|
end
|
146
156
|
|
@@ -149,9 +159,10 @@ class DeathMasterFileLoader
|
|
149
159
|
#The downside is it's really slow.
|
150
160
|
def active_record_file_load
|
151
161
|
puts 'Importing file into database. This could take many minutes.'
|
162
|
+
yield 'Importing file into database. This could take many minutes.' if block_given?
|
152
163
|
|
153
|
-
@download_file.each_with_index do |line,i|
|
154
|
-
action
|
164
|
+
@download_file.each_with_index do |line, i|
|
165
|
+
action = record_action(line)
|
155
166
|
attributes_hash = text_to_hash(line)
|
156
167
|
if action == 'D'
|
157
168
|
DeathMasterFile.destroy_all(['social_security_number = ?', attributes_hash[:social_security_number]])
|
@@ -175,26 +186,28 @@ class DeathMasterFileLoader
|
|
175
186
|
# }
|
176
187
|
|
177
188
|
case action
|
178
|
-
|
179
|
-
|
180
|
-
DeathMasterFile.create(attributes_hash)
|
181
|
-
else
|
182
|
-
dmf = DeathMasterFile.find_by_social_security_number(attributes_hash[:social_security_number])
|
183
|
-
if dmf
|
184
|
-
#a record already exists, update this record
|
185
|
-
dmf.update_attributes(attributes_hash)
|
186
|
-
else
|
187
|
-
#create a new record
|
189
|
+
when '', nil, ' '
|
190
|
+
#the initial file leaves this field blank
|
188
191
|
DeathMasterFile.create(attributes_hash)
|
189
|
-
|
192
|
+
else
|
193
|
+
dmf = DeathMasterFile.find_by_social_security_number(attributes_hash[:social_security_number])
|
194
|
+
if dmf
|
195
|
+
#a record already exists, update this record
|
196
|
+
dmf.update_attributes(attributes_hash)
|
197
|
+
else
|
198
|
+
#create a new record
|
199
|
+
DeathMasterFile.create(attributes_hash)
|
200
|
+
end
|
190
201
|
end
|
191
202
|
end
|
192
|
-
|
193
|
-
|
194
|
-
|
203
|
+
if (i % 2500 == 0) && (i > 0)
|
204
|
+
puts "#{i} records processed."
|
205
|
+
yield "#{i} records processed." if block_given?
|
206
|
+
end
|
195
207
|
end
|
196
208
|
|
197
209
|
puts "Import complete."
|
210
|
+
yield "Import complete." if block_given?
|
198
211
|
end
|
199
212
|
|
200
213
|
# For mysql, use:
|
@@ -203,6 +216,7 @@ class DeathMasterFileLoader
|
|
203
216
|
# see http://dev.mysql.com/doc/refman/5.1/en/load-data.html
|
204
217
|
def bulk_mysql_update(csv_file)
|
205
218
|
puts "Importing into Mysql..."
|
219
|
+
yield "Importing into Mysql..." if block_given?
|
206
220
|
|
207
221
|
#delete all the 'D' records
|
208
222
|
DeathMasterFile.delete_all(:social_security_number => @delete_ssns)
|
@@ -215,29 +229,28 @@ class DeathMasterFileLoader
|
|
215
229
|
|
216
230
|
DeathMasterFile.connection.execute(mysql_command)
|
217
231
|
puts "Mysql import complete."
|
232
|
+
yield "Mysql import complete." if block_given?
|
218
233
|
|
219
234
|
end
|
220
235
|
|
221
236
|
def record_action(line)
|
222
|
-
line[0,1].to_s.strip
|
237
|
+
line[0, 1].to_s.strip
|
223
238
|
end
|
224
239
|
|
225
240
|
def text_to_hash(line)
|
226
241
|
|
227
|
-
{:as_of
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
rescue Exception => e
|
241
|
-
puts '@@@@@@@@@ Error = ' + e.message + ': ' + line.inspect
|
242
|
+
{:as_of => @file_as_of.to_date.to_s(:db),
|
243
|
+
:social_security_number => line[1, 9].to_s.strip,
|
244
|
+
:last_name => line[10, 20].to_s.strip,
|
245
|
+
:name_suffix => line[30, 4].to_s.strip,
|
246
|
+
:first_name => line[34, 15].to_s.strip,
|
247
|
+
:middle_name => line[49, 15].to_s.strip,
|
248
|
+
:verify_proof_code => line[64, 1].to_s.strip,
|
249
|
+
:date_of_death => (Date.strptime(line[65, 8].to_s.strip, '%m%d%Y') rescue nil),
|
250
|
+
:date_of_birth => (Date.strptime(line[73, 8].to_s.strip, '%m%d%Y') rescue nil),
|
251
|
+
# - must be code between 01 and 65 or else nil.
|
252
|
+
:state_of_residence => (line[81, 2].to_s.strip.between?('01', '65') ? line[81, 2].to_s.strip : nil),
|
253
|
+
:last_known_zip_residence => line[83, 5].to_s.strip,
|
254
|
+
:last_known_zip_payment => line[88, 5].to_s.strip}
|
242
255
|
end
|
243
256
|
end
|
@@ -23,7 +23,9 @@ class SsnHighGroupCodeLoader
|
|
23
23
|
file_name = "HG#{run_file_month}#{string_day}#{string_year}#{mod}.txt"
|
24
24
|
text = Net::HTTP.get(URI.parse("http://www.socialsecurity.gov/employer/#{url_mod}/#{file_name}"))
|
25
25
|
unless text.include? 'File Not Found'
|
26
|
-
create_records(parse_text(text),extract_as_of_date(text))
|
26
|
+
create_records(parse_text(text),extract_as_of_date(text)) do |status|
|
27
|
+
yield status if block_given?
|
28
|
+
end
|
27
29
|
file_processed = true
|
28
30
|
break
|
29
31
|
end
|
@@ -51,11 +53,13 @@ class SsnHighGroupCodeLoader
|
|
51
53
|
def self.create_records(area_groups,file_as_of)
|
52
54
|
if already_loaded?(file_as_of)
|
53
55
|
puts "File as of #{file_as_of} has already been loaded."
|
56
|
+
yield "File as of #{file_as_of} has already been loaded." if block_given?
|
54
57
|
else
|
55
58
|
area_groups.each do |area_group|
|
56
59
|
SsnHighGroupCode.create(area_group.merge!(:as_of => file_as_of.to_s(:db)))
|
57
60
|
end
|
58
61
|
puts "File as of #{file_as_of} loaded."
|
62
|
+
yield "File as of #{file_as_of} loaded." if block_given?
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
@@ -117,7 +117,7 @@
|
|
117
117
|
|
118
118
|
<div class="method-heading">
|
119
119
|
<a href="#M000005" class="method-signature">
|
120
|
-
<span class="method-name">load_update_files_from_web</span><span class="method-args">()</span>
|
120
|
+
<span class="method-name">load_update_files_from_web</span><span class="method-args">() {|"Loading file| ...}</span>
|
121
121
|
</a>
|
122
122
|
</div>
|
123
123
|
|
@@ -130,15 +130,19 @@ loaded, and loads each missing file in sequence up to the current file.
|
|
130
130
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
131
131
|
<div class="method-source-code" id="M000005-source">
|
132
132
|
<pre>
|
133
|
-
<span class="ruby-comment cmt"># File lib/ssn_validator/models/death_master_file_loader.rb, line
|
133
|
+
<span class="ruby-comment cmt"># File lib/ssn_validator/models/death_master_file_loader.rb, line 77</span>
|
134
134
|
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load_update_files_from_web</span>
|
135
|
-
<span class="ruby-identifier">max_as_of</span>
|
136
|
-
<span class="ruby-identifier">run_file_date</span>
|
135
|
+
<span class="ruby-identifier">max_as_of</span> = <span class="ruby-constant">DeathMasterFile</span>.<span class="ruby-identifier">maximum</span>(<span class="ruby-identifier">:as_of</span>)
|
136
|
+
<span class="ruby-identifier">run_file_date</span> = <span class="ruby-identifier">max_as_of</span>.<span class="ruby-identifier">beginning_of_month</span>.<span class="ruby-identifier">next_month</span>
|
137
137
|
<span class="ruby-identifier">last_file_date</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">today</span>.<span class="ruby-identifier">beginning_of_month</span>
|
138
138
|
<span class="ruby-keyword kw">while</span> <span class="ruby-identifier">run_file_date</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">last_file_date</span>
|
139
139
|
<span class="ruby-identifier">url</span> = <span class="ruby-node">"https://dmf.ntis.gov/dmldata/monthly/MA#{run_file_date.strftime("%y%m%d")}"</span>
|
140
140
|
<span class="ruby-identifier">puts</span> <span class="ruby-node">"Loading file #{url}"</span>
|
141
|
-
<span class="ruby-
|
141
|
+
<span class="ruby-keyword kw">yield</span> <span class="ruby-node">"Loading file #{url}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
142
|
+
<span class="ruby-identifier">dmf</span> = <span class="ruby-constant">DeathMasterFileLoader</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">url</span>, <span class="ruby-identifier">run_file_date</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-value str">"%Y-%m-%d"</span>)){<span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>}
|
143
|
+
<span class="ruby-identifier">dmf</span>.<span class="ruby-identifier">load_file</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span>
|
144
|
+
<span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
145
|
+
<span class="ruby-keyword kw">end</span>
|
142
146
|
<span class="ruby-identifier">run_file_date</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">month</span>
|
143
147
|
<span class="ruby-keyword kw">end</span>
|
144
148
|
<span class="ruby-keyword kw">end</span>
|
@@ -152,7 +156,7 @@ loaded, and loads each missing file in sequence up to the current file.
|
|
152
156
|
|
153
157
|
<div class="method-heading">
|
154
158
|
<a href="#M000001" class="method-signature">
|
155
|
-
<span class="method-name">new</span><span class="method-args">(path_or_url,file_as_of)</span>
|
159
|
+
<span class="method-name">new</span><span class="method-args">(path_or_url, file_as_of) {|status if block_given?| ...}</span>
|
156
160
|
</a>
|
157
161
|
</div>
|
158
162
|
|
@@ -167,10 +171,10 @@ data is accurate.
|
|
167
171
|
<div class="method-source-code" id="M000001-source">
|
168
172
|
<pre>
|
169
173
|
<span class="ruby-comment cmt"># File lib/ssn_validator/models/death_master_file_loader.rb, line 11</span>
|
170
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">path_or_url</span
|
174
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">path_or_url</span>, <span class="ruby-identifier">file_as_of</span>)
|
171
175
|
<span class="ruby-ivar">@file_path_or_url</span> = <span class="ruby-identifier">path_or_url</span>
|
172
|
-
<span class="ruby-ivar">@file_as_of</span>
|
173
|
-
<span class="ruby-identifier">valid?</span>
|
176
|
+
<span class="ruby-ivar">@file_as_of</span> = <span class="ruby-identifier">file_as_of</span>
|
177
|
+
<span class="ruby-identifier">valid?</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>}
|
174
178
|
<span class="ruby-keyword kw">end</span>
|
175
179
|
</pre>
|
176
180
|
</div>
|
@@ -184,7 +188,7 @@ data is accurate.
|
|
184
188
|
|
185
189
|
<div class="method-heading">
|
186
190
|
<a href="#M000004" class="method-signature">
|
187
|
-
<span class="method-name">get_file_from_web</span><span class="method-args">()</span>
|
191
|
+
<span class="method-name">get_file_from_web</span><span class="method-args">() {|"%d%% done (%d of %d" % [(size * 100) / total, size, total])| ...}</span>
|
188
192
|
</a>
|
189
193
|
</div>
|
190
194
|
|
@@ -193,18 +197,18 @@ data is accurate.
|
|
193
197
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
194
198
|
<div class="method-source-code" id="M000004-source">
|
195
199
|
<pre>
|
196
|
-
<span class="ruby-comment cmt"># File lib/ssn_validator/models/death_master_file_loader.rb, line
|
200
|
+
<span class="ruby-comment cmt"># File lib/ssn_validator/models/death_master_file_loader.rb, line 47</span>
|
197
201
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_file_from_web</span>
|
198
|
-
<span class="ruby-identifier">uri</span>
|
202
|
+
<span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-ivar">@file_path_or_url</span>)
|
199
203
|
|
200
204
|
<span class="ruby-identifier">request</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">request_uri</span>)
|
201
|
-
<span class="ruby-identifier">request</span>.<span class="ruby-identifier">basic_auth</span>(<span class="ruby-constant">SsnValidator</span><span class="ruby-operator">::</span><span class="ruby-constant">Ntis</span>.<span class="ruby-identifier">user_name</span
|
205
|
+
<span class="ruby-identifier">request</span>.<span class="ruby-identifier">basic_auth</span>(<span class="ruby-constant">SsnValidator</span><span class="ruby-operator">::</span><span class="ruby-constant">Ntis</span>.<span class="ruby-identifier">user_name</span>, <span class="ruby-constant">SsnValidator</span><span class="ruby-operator">::</span><span class="ruby-constant">Ntis</span>.<span class="ruby-identifier">password</span>)
|
202
206
|
|
203
|
-
<span class="ruby-identifier">http</span>
|
204
|
-
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span>
|
207
|
+
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">host</span>, <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">port</span>)
|
208
|
+
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = (<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">port</span> <span class="ruby-operator">==</span> <span class="ruby-value">443</span>)
|
205
209
|
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">verify_mode</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">VERIFY_NONE</span>
|
206
210
|
|
207
|
-
<span class="ruby-identifier">csv_file</span>
|
211
|
+
<span class="ruby-identifier">csv_file</span> = <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@file_path_or_url</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'/'</span>).<span class="ruby-identifier">last</span>) <span class="ruby-comment cmt"># create temp file for the raw file.</span>
|
208
212
|
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">request</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
|
209
213
|
<span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Invalid URL: #{@file_path_or_url}"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPNotFound</span>)
|
210
214
|
<span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Authorization Required: Invalid username or password. Set the variables SsnValidator::Ntis.user_name and SsnValidator::Ntis.password in your environment.rb file."</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPUnauthorized</span>)
|
@@ -213,6 +217,7 @@ data is accurate.
|
|
213
217
|
<span class="ruby-identifier">size</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">chunk</span>.<span class="ruby-identifier">size</span>
|
214
218
|
<span class="ruby-identifier">csv_file</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">chunk</span>
|
215
219
|
<span class="ruby-identifier">puts</span> <span class="ruby-value str">"%d%% done (%d of %d)"</span> <span class="ruby-operator">%</span> [(<span class="ruby-identifier">size</span> <span class="ruby-operator">*</span> <span class="ruby-value">100</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">total</span>, <span class="ruby-identifier">size</span>, <span class="ruby-identifier">total</span>]
|
220
|
+
<span class="ruby-keyword kw">yield</span>(<span class="ruby-value str">"%d%% done (%d of %d)"</span> <span class="ruby-operator">%</span> [(<span class="ruby-identifier">size</span> <span class="ruby-operator">*</span> <span class="ruby-value">100</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">total</span>, <span class="ruby-identifier">size</span>, <span class="ruby-identifier">total</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
216
221
|
<span class="ruby-keyword kw">end</span>
|
217
222
|
|
218
223
|
<span class="ruby-keyword kw">end</span>
|
@@ -229,7 +234,7 @@ data is accurate.
|
|
229
234
|
|
230
235
|
<div class="method-heading">
|
231
236
|
<a href="#M000003" class="method-signature">
|
232
|
-
<span class="method-name">load_file</span><span class="method-args">()</span>
|
237
|
+
<span class="method-name">load_file</span><span class="method-args">() {|"Converting file to csv format for Mysql import. This could take several minutes." if block_given?| ...}</span>
|
233
238
|
</a>
|
234
239
|
</div>
|
235
240
|
|
@@ -243,12 +248,13 @@ data is accurate.
|
|
243
248
|
|
244
249
|
<span class="ruby-keyword kw">if</span> <span class="ruby-constant">DeathMasterFile</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">ConnectionAdapters</span><span class="ruby-operator">::</span><span class="ruby-constant">MysqlAdapter</span>) <span class="ruby-operator">||</span> <span class="ruby-constant">DeathMasterFile</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">ConnectionAdapters</span><span class="ruby-operator">::</span><span class="ruby-constant">JdbcAdapter</span>)
|
245
250
|
<span class="ruby-identifier">puts</span> <span class="ruby-value str">"Converting file to csv format for Mysql import. This could take several minutes."</span>
|
251
|
+
<span class="ruby-keyword kw">yield</span> <span class="ruby-value str">"Converting file to csv format for Mysql import. This could take several minutes."</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
246
252
|
|
247
|
-
<span class="ruby-identifier">csv_file</span> = <span class="ruby-identifier">convert_file_to_csv</span>
|
253
|
+
<span class="ruby-identifier">csv_file</span> = <span class="ruby-identifier">convert_file_to_csv</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>}
|
248
254
|
|
249
|
-
<span class="ruby-identifier">bulk_mysql_update</span>(<span class="ruby-identifier">csv_file</span>)
|
255
|
+
<span class="ruby-identifier">bulk_mysql_update</span>(<span class="ruby-identifier">csv_file</span>){<span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>}
|
250
256
|
<span class="ruby-keyword kw">else</span>
|
251
|
-
<span class="ruby-identifier">active_record_file_load</span>
|
257
|
+
<span class="ruby-identifier">active_record_file_load</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>}
|
252
258
|
<span class="ruby-keyword kw">end</span>
|
253
259
|
|
254
260
|
<span class="ruby-keyword kw">end</span>
|
@@ -262,7 +268,7 @@ data is accurate.
|
|
262
268
|
|
263
269
|
<div class="method-heading">
|
264
270
|
<a href="#M000002" class="method-signature">
|
265
|
-
<span class="method-name">valid?</span><span class="method-args">()</span>
|
271
|
+
<span class="method-name">valid?</span><span class="method-args">() {|status if block_given?| ...}</span>
|
266
272
|
</a>
|
267
273
|
</div>
|
268
274
|
|
@@ -281,7 +287,7 @@ data is accurate.
|
|
281
287
|
<span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-ivar">@file_path_or_url</span>)
|
282
288
|
<span class="ruby-ivar">@download_file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-ivar">@file_path_or_url</span>)
|
283
289
|
<span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-ivar">@file_path_or_url</span>).<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>)
|
284
|
-
<span class="ruby-ivar">@download_file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">get_file_from_web</span>)
|
290
|
+
<span class="ruby-ivar">@download_file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">get_file_from_web</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>})
|
285
291
|
<span class="ruby-keyword kw">else</span>
|
286
292
|
<span class="ruby-identifier">raise</span>(<span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ENOENT</span>, <span class="ruby-ivar">@file_path_or_url</span>)
|
287
293
|
<span class="ruby-keyword kw">end</span>
|
@@ -114,7 +114,7 @@
|
|
114
114
|
|
115
115
|
<div class="method-heading">
|
116
116
|
<a href="#M000006" class="method-signature">
|
117
|
-
<span class="method-name">load_all_high_group_codes_files</span><span class="method-args">()</span>
|
117
|
+
<span class="method-name">load_all_high_group_codes_files</span><span class="method-args">() {|status if block_given?| ...}</span>
|
118
118
|
</a>
|
119
119
|
</div>
|
120
120
|
|
@@ -146,7 +146,9 @@
|
|
146
146
|
<span class="ruby-identifier">file_name</span> = <span class="ruby-node">"HG#{run_file_month}#{string_day}#{string_year}#{mod}.txt"</span>
|
147
147
|
<span class="ruby-identifier">text</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-node">"http://www.socialsecurity.gov/employer/#{url_mod}/#{file_name}"</span>))
|
148
148
|
<span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">text</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">'File Not Found'</span>
|
149
|
-
<span class="ruby-identifier">create_records</span>(<span class="ruby-identifier">parse_text</span>(<span class="ruby-identifier">text</span>),<span class="ruby-identifier">extract_as_of_date</span>(<span class="ruby-identifier">text</span>))
|
149
|
+
<span class="ruby-identifier">create_records</span>(<span class="ruby-identifier">parse_text</span>(<span class="ruby-identifier">text</span>),<span class="ruby-identifier">extract_as_of_date</span>(<span class="ruby-identifier">text</span>)) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span>
|
150
|
+
<span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
151
|
+
<span class="ruby-keyword kw">end</span>
|
150
152
|
<span class="ruby-identifier">file_processed</span> = <span class="ruby-keyword kw">true</span>
|
151
153
|
<span class="ruby-keyword kw">break</span>
|
152
154
|
<span class="ruby-keyword kw">end</span>
|
@@ -180,7 +182,7 @@ href="http://www.socialsecurity.gov/employer/ssns/highgroup.txt">www.socialsecur
|
|
180
182
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
181
183
|
<div class="method-source-code" id="M000007-source">
|
182
184
|
<pre>
|
183
|
-
<span class="ruby-comment cmt"># File lib/ssn_validator/models/ssn_high_group_code_loader.rb, line
|
185
|
+
<span class="ruby-comment cmt"># File lib/ssn_validator/models/ssn_high_group_code_loader.rb, line 41</span>
|
184
186
|
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load_current_high_group_codes_file</span>
|
185
187
|
<span class="ruby-identifier">text</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-value str">'http://www.socialsecurity.gov/employer/ssns/highgroup.txt'</span>))
|
186
188
|
<span class="ruby-identifier">create_records</span>(<span class="ruby-identifier">parse_text</span>(<span class="ruby-identifier">text</span>),<span class="ruby-identifier">extract_as_of_date</span>(<span class="ruby-identifier">text</span>))
|
data/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Mon, 07 Mar 2011 16:17:46 -0500
|
data/rdoc/index.html
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
<!--
|
7
7
|
|
8
|
-
ssn_validator 1.0.
|
8
|
+
ssn_validator 1.0.9
|
9
9
|
|
10
10
|
-->
|
11
11
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
12
12
|
<head>
|
13
|
-
<title>ssn_validator 1.0.
|
13
|
+
<title>ssn_validator 1.0.9</title>
|
14
14
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
15
15
|
</head>
|
16
16
|
<frameset rows="20%, 80%">
|
data/ssn_validator.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ssn_validator}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kevin Tyll"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-07}
|
13
13
|
s.description = %q{Validates whether an SSN has likely been issued or not.}
|
14
14
|
s.email = %q{kevintyll@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 9
|
9
|
+
version: 1.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kevin Tyll
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-03-07 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|