rsmart_toolbox 0.6 → 0.7
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +1 -1
- data/lib/rsmart_toolbox/etl/grm.rb +182 -34
- data/lib/rsmart_toolbox/etl.rb +13 -1
- data/lib/rsmart_toolbox/version.rb +2 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8df8ae09435c7a5b1e5020d14b9d25cd8139eab0
|
4
|
+
data.tar.gz: 2a344b354dab13174e72ef5ecf07965be1cc7847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 401fc57dff32377887e72ee52c6438828da22abc8dd60f3dcd5cff9f5bcfbefc5643f8ac4e5911ef93a2aa1257a61be5de470467ffb104373d9bb5a53b41a342
|
7
|
+
data.tar.gz: 4547735ef1c185689c2fb76d2e38caf4e373292e30bcba2aa65563aece83a090821f6929beb897e574354229d527be7a057cfe72a05f5b4e860d6497afed2f37
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -16,9 +16,17 @@
|
|
16
16
|
|
17
17
|
require "rsmart_toolbox/etl"
|
18
18
|
|
19
|
+
# rSmart Grant and Research Management methods.
|
19
20
|
module Rsmart::ETL::GRM
|
20
21
|
|
21
|
-
|
22
|
+
# Parses the <tt>ROLODEX_ID</tt> by column :name and mutates the SQL statement accordingly.
|
23
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
24
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
25
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
26
|
+
# @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_integer!}.
|
27
|
+
# @return [void]
|
28
|
+
# @see parse_integer!
|
29
|
+
def self.parse_rolodex_id!(row, insert_str, values_str, opt={ name: 'ROLODEX_ID', required: true, length: 6 })
|
22
30
|
# `ROLODEX_ID` decimal(6,0) NOT NULL DEFAULT '0',
|
23
31
|
opt[:name] = "ROLODEX_ID" if opt[:name].nil?
|
24
32
|
opt[:required] = true if opt[:required].nil?
|
@@ -26,21 +34,42 @@ module Rsmart::ETL::GRM
|
|
26
34
|
Rsmart::ETL::parse_integer! row, insert_str, values_str, opt
|
27
35
|
end
|
28
36
|
|
29
|
-
|
37
|
+
# Parses the <tt>COUNTRY_CODE</tt> by column :name and mutates the SQL statement accordingly.
|
38
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
39
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
40
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
41
|
+
# @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}.
|
42
|
+
# @return [void]
|
43
|
+
# @see parse_string!
|
44
|
+
def self.parse_country_code!(row, insert_str, values_str, opt={ name: 'COUNTRY_CODE', length: 3 })
|
30
45
|
# `COUNTRY_CODE` char(3) COLLATE utf8_bin DEFAULT NULL,
|
31
46
|
opt[:name] = "COUNTRY_CODE" if opt[:name].nil?
|
32
47
|
opt[:length] = 3 if opt[:length].nil?
|
33
48
|
Rsmart::ETL::parse_string! row, insert_str, values_str, opt
|
34
49
|
end
|
35
50
|
|
36
|
-
|
51
|
+
# Parses the <tt>STATE</tt> by column :name and mutates the SQL statement accordingly.
|
52
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
53
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
54
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
55
|
+
# @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}.
|
56
|
+
# @return [void]
|
57
|
+
# @see parse_string!
|
58
|
+
def self.parse_state!(row, insert_str, values_str, opt={ name: 'STATE', length: 30 })
|
37
59
|
# `STATE` varchar(30) COLLATE utf8_bin DEFAULT NULL,
|
38
60
|
opt[:name] = "STATE" if opt[:name].nil?
|
39
61
|
opt[:length] = 30 if opt[:length].nil?
|
40
62
|
Rsmart::ETL::parse_string! row, insert_str, values_str, opt
|
41
63
|
end
|
42
64
|
|
43
|
-
|
65
|
+
# Parses the <tt>SPONSOR_CODE</tt> by column :name and mutates the SQL statement accordingly.
|
66
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
67
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
68
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
69
|
+
# @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}.
|
70
|
+
# @return [void]
|
71
|
+
# @see parse_string!
|
72
|
+
def self.parse_sponsor_code!(row, insert_str, values_str, opt={ name: 'SPONSOR_CODE', required: true, length: 6 })
|
44
73
|
# `SPONSOR_CODE` char(6) COLLATE utf8_bin NOT NULL DEFAULT '',
|
45
74
|
opt[:name] = "SPONSOR_CODE" if opt[:name].nil?
|
46
75
|
opt[:required] = true if opt[:required].nil?
|
@@ -48,14 +77,28 @@ module Rsmart::ETL::GRM
|
|
48
77
|
Rsmart::ETL::parse_string! row, insert_str, values_str, opt
|
49
78
|
end
|
50
79
|
|
51
|
-
|
80
|
+
# Parses the <tt>POSTAL_CODE</tt> by column :name and mutates the SQL statement accordingly.
|
81
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
82
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
83
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
84
|
+
# @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}.
|
85
|
+
# @return [void]
|
86
|
+
# @see parse_string!
|
87
|
+
def self.parse_postal_code!(row, insert_str, values_str, opt={ name: 'POSTAL_CODE', length: 15 })
|
52
88
|
# `POSTAL_CODE` varchar(15) COLLATE utf8_bin DEFAULT NULL,
|
53
89
|
opt[:name] = "POSTAL_CODE" if opt[:name].nil?
|
54
90
|
opt[:length] = 15 if opt[:length].nil?
|
55
91
|
Rsmart::ETL::parse_string! row, insert_str, values_str, opt
|
56
92
|
end
|
57
93
|
|
58
|
-
|
94
|
+
# Parses the <tt>OWNED_BY_UNIT</tt> by column :name and mutates the SQL statement accordingly.
|
95
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
96
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
97
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
98
|
+
# @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}.
|
99
|
+
# @return [void]
|
100
|
+
# @see parse_string!
|
101
|
+
def self.parse_owned_by_unit!(row, insert_str, values_str, opt={ name: 'OWNED_BY_UNIT', required: true, length: 8 })
|
59
102
|
# `OWNED_BY_UNIT` varchar(8) COLLATE utf8_bin NOT NULL,
|
60
103
|
opt[:name] = "OWNED_BY_UNIT" if opt[:name].nil?
|
61
104
|
opt[:required] = true if opt[:required].nil?
|
@@ -63,7 +106,14 @@ module Rsmart::ETL::GRM
|
|
63
106
|
Rsmart::ETL::parse_string! row, insert_str, values_str, opt
|
64
107
|
end
|
65
108
|
|
66
|
-
|
109
|
+
# Parse an <tt>EMAIL_ADDRESS</tt> from a String.
|
110
|
+
# @note The result is validated against a email address RegExp.
|
111
|
+
# @param [String] str the String to be parsed.
|
112
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
113
|
+
# @return [String] the parsed <tt>EMAIL_ADDRESS</tt>.
|
114
|
+
# @raise [TextParseError] if the email address is not valid.
|
115
|
+
# @see parse_string
|
116
|
+
def self.parse_email_address(str, opt={ name: 'EMAIL_ADDRESS', length: 60 })
|
67
117
|
# `EMAIL_ADDRESS` varchar(60) COLLATE utf8_bin DEFAULT NULL,
|
68
118
|
opt[:name] = "EMAIL_ADDRESS" if opt[:name].nil?
|
69
119
|
opt[:length] = 60 if opt[:length].nil?
|
@@ -71,14 +121,27 @@ module Rsmart::ETL::GRM
|
|
71
121
|
return Rsmart::ETL::parse_string str, opt
|
72
122
|
end
|
73
123
|
|
74
|
-
|
124
|
+
# Parses the <tt>EMAIL_ADDRESS</tt> by column :name and mutates the SQL statement accordingly.
|
125
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
126
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
127
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
128
|
+
# @param opt [Hash] options Hash will be passed through to {parse_email_address}.
|
129
|
+
# @return [void]
|
130
|
+
# @see parse_email_address
|
131
|
+
# @see mutate_sql_stmt!
|
132
|
+
def self.parse_email_address!(row, insert_str, values_str, opt={ name: 'EMAIL_ADDRESS' })
|
75
133
|
# `EMAIL_ADDRESS` varchar(60) COLLATE utf8_bin DEFAULT NULL,
|
76
134
|
opt[:name] = "EMAIL_ADDRESS" if opt[:name].nil?
|
77
135
|
email_address = parse_email_address row[ Rsmart::ETL::to_symbol( opt[:name] ) ]
|
78
136
|
Rsmart::ETL::mutate_sql_stmt! insert_str, opt[:name], values_str, email_address
|
79
137
|
end
|
80
138
|
|
81
|
-
|
139
|
+
# Parse a <tt>PRNCPL_ID</tt> from a String.
|
140
|
+
# @param [String] str the String to be parsed.
|
141
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
142
|
+
# @return [String] the parsed <tt>PRNCPL_ID</tt>.
|
143
|
+
# @see parse_string
|
144
|
+
def self.parse_principal_id(str, opt={ name: 'PRNCPL_ID', required: true, length: 40 })
|
82
145
|
# `PRNCPL_ID` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '',
|
83
146
|
opt[:name] = "PRNCPL_ID" if opt[:name].nil?
|
84
147
|
opt[:required] = true if opt[:required].nil?
|
@@ -86,7 +149,12 @@ module Rsmart::ETL::GRM
|
|
86
149
|
Rsmart::ETL::parse_string str, opt
|
87
150
|
end
|
88
151
|
|
89
|
-
|
152
|
+
# Parse a <tt>PRNCPL_NM</tt> from a String.
|
153
|
+
# @param [String] str the String to be parsed.
|
154
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
155
|
+
# @return [String] the parsed <tt>PRNCPL_NM</tt>.
|
156
|
+
# @see parse_string
|
157
|
+
def self.parse_principal_name(str, opt={ name: 'PRNCPL_NM', required: true, length: 100 })
|
90
158
|
# `PRNCPL_NM` varchar(100) COLLATE utf8_bin NOT NULL,
|
91
159
|
opt[:name] = "PRNCPL_NM" if opt[:name].nil?
|
92
160
|
opt[:length] = 100 if opt[:length].nil?
|
@@ -98,36 +166,65 @@ module Rsmart::ETL::GRM
|
|
98
166
|
return prncpl_nm
|
99
167
|
end
|
100
168
|
|
101
|
-
|
169
|
+
# Parse an <tt>EMP_STAT_CD</tt> from a String.
|
170
|
+
# @param [String] str the String to be parsed.
|
171
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
172
|
+
# @return [String] the parsed <tt>EMP_STAT_CD</tt>.
|
173
|
+
# @raise [TextParseError] if the <tt>EMP_STAT_CD</tt> is not valid.
|
174
|
+
# @see parse_string
|
175
|
+
def self.parse_emp_stat_cd(str, opt={ name: 'EMP_STAT_CD', valid_values: /^(A|D|L|N|P|R|S|T)$/i })
|
102
176
|
# `EMP_STAT_CD` varchar(40) COLLATE utf8_bin DEFAULT NULL,
|
103
177
|
opt[:name] = "EMP_STAT_CD" if opt[:name].nil?
|
104
178
|
opt[:valid_values] = /^(A|D|L|N|P|R|S|T)$/i if opt[:valid_values].nil?
|
105
179
|
return Rsmart::ETL::parse_flag str, opt
|
106
180
|
end
|
107
181
|
|
108
|
-
|
182
|
+
# Parse an <tt>EMP_TYP_CD</tt> from a String.
|
183
|
+
# @param [String] str the String to be parsed.
|
184
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
185
|
+
# @return [String] the parsed <tt>EMP_TYP_CD</tt>.
|
186
|
+
# @raise [TextParseError] if the <tt>EMP_TYP_CD</tt> is not valid.
|
187
|
+
# @see parse_string
|
188
|
+
def self.parse_emp_typ_cd(str, opt={ name: 'EMP_TYP_CD', valid_values: /^(N|O|P)$/i })
|
109
189
|
# `EMP_TYP_CD` varchar(40) COLLATE utf8_bin DEFAULT NULL,
|
110
190
|
opt[:name] = "EMP_TYP_CD" if opt[:name].nil?
|
111
191
|
opt[:valid_values] = /^(N|O|P)$/i if opt[:valid_values].nil?
|
112
192
|
return Rsmart::ETL::parse_flag str, opt
|
113
193
|
end
|
114
194
|
|
115
|
-
|
116
|
-
|
195
|
+
# Parse an <tt>ADDR_TYP_CD</tt> from a String.
|
196
|
+
# @param [String] str the String to be parsed.
|
197
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
198
|
+
# @return [String] the parsed <tt>ADDR_TYP_CD</tt>.
|
199
|
+
# @raise [TextParseError] if the <tt>ADDR_TYP_CD</tt> is not valid.
|
200
|
+
# @see parse_string
|
201
|
+
def self.parse_address_type_code(str, opt={ name: 'ADDR_TYP_CD', length: 3, valid_values: /^(HM|OTH|WRK)$/i })
|
117
202
|
opt[:name] = "ADDR_TYP_CD" if opt[:name].nil?
|
118
203
|
opt[:length] = 3 if opt[:length].nil?
|
119
204
|
opt[:valid_values] = /^(HM|OTH|WRK)$/i if opt[:valid_values].nil?
|
120
205
|
return Rsmart::ETL::parse_flag str, opt
|
121
206
|
end
|
122
207
|
|
123
|
-
|
208
|
+
# Parse a <tt>NM_TYP_CD</tt> from a String.
|
209
|
+
# @param [String] str the String to be parsed.
|
210
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
211
|
+
# @return [String] the parsed <tt>NM_TYP_CD</tt>.
|
212
|
+
# @raise [TextParseError] if the <tt>NM_TYP_CD</tt> is not valid.
|
213
|
+
# @see parse_string
|
214
|
+
def self.parse_name_code(str, opt={ name: 'NM_TYP_CD', length: 4, valid_values: /^(OTH|PRFR|PRM)$/i })
|
124
215
|
opt[:name] = "NM_TYP_CD" if opt[:name].nil?
|
125
216
|
opt[:length] = 4 if opt[:length].nil?
|
126
217
|
opt[:valid_values] = /^(OTH|PRFR|PRM)$/i if opt[:valid_values].nil?
|
127
218
|
return Rsmart::ETL::parse_flag str, opt
|
128
219
|
end
|
129
220
|
|
130
|
-
|
221
|
+
# Parse a <tt>PREFIX_NM</tt> from a String.
|
222
|
+
# @param [String] str the String to be parsed.
|
223
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
224
|
+
# @return [String] the parsed <tt>PREFIX_NM</tt>.
|
225
|
+
# @raise [TextParseError] if the <tt>PREFIX_NM</tt> is not valid.
|
226
|
+
# @see parse_string
|
227
|
+
def self.parse_prefix(str, opt={ name: 'PREFIX_NM', length: 3, valid_values: /^(Ms|Mrs|Mr|Dr)?$/ })
|
131
228
|
opt[:name] = "PREFIX_NM" if opt[:name].nil?
|
132
229
|
opt[:length] = 3 if opt[:length].nil?
|
133
230
|
opt[:valid_values] = /^(Ms|Mrs|Mr|Dr)?$/ if opt[:valid_values].nil?
|
@@ -135,7 +232,13 @@ module Rsmart::ETL::GRM
|
|
135
232
|
return Rsmart::ETL::parse_flag str, opt
|
136
233
|
end
|
137
234
|
|
138
|
-
|
235
|
+
# Parse a <tt>SUFFIX_NM</tt> from a String.
|
236
|
+
# @param [String] str the String to be parsed.
|
237
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
238
|
+
# @return [String] the parsed <tt>SUFFIX_NM</tt>.
|
239
|
+
# @raise [TextParseError] if the <tt>SUFFIX_NM</tt> is not valid.
|
240
|
+
# @see parse_string
|
241
|
+
def self.parse_suffix(str, opt={ name: 'SUFFIX_NM', length: 3, valid_values: /^(Jr|Sr|Mr|Md)?$/ })
|
139
242
|
opt[:name] = "SUFFIX_NM" if opt[:name].nil?
|
140
243
|
opt[:length] = 3 if opt[:length].nil?
|
141
244
|
opt[:valid_values] = /^(Jr|Sr|Mr|Md)?$/ if opt[:valid_values].nil?
|
@@ -143,43 +246,76 @@ module Rsmart::ETL::GRM
|
|
143
246
|
return Rsmart::ETL::parse_flag str, opt
|
144
247
|
end
|
145
248
|
|
146
|
-
|
147
|
-
|
249
|
+
# Parse a <tt>PHONE_TYP_CD</tt> from a String.
|
250
|
+
# @param [String] str the String to be parsed.
|
251
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
252
|
+
# @return [String] the parsed <tt>PHONE_TYP_CD</tt>.
|
253
|
+
# @raise [TextParseError] if the <tt>PHONE_TYP_CD</tt> is not valid.
|
254
|
+
# @see parse_string
|
255
|
+
def self.parse_phone_type(str, opt={ name: 'PHONE_TYP_CD', length: 3, valid_values: /^(FAX|HM|MBL|OTH|WRK)$/i })
|
148
256
|
opt[:name] = "PHONE_TYP_CD" if opt[:name].nil?
|
149
257
|
opt[:length] = 3 if opt[:length].nil?
|
150
258
|
opt[:valid_values] = /^(FAX|HM|MBL|OTH|WRK)$/i if opt[:valid_values].nil?
|
151
259
|
return Rsmart::ETL::parse_flag str, opt
|
152
260
|
end
|
153
261
|
|
154
|
-
|
155
|
-
|
262
|
+
# Parse a <tt>PHONE_NBR</tt> from a String.
|
263
|
+
# @param [String] str the String to be parsed.
|
264
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
265
|
+
# @return [String] the parsed <tt>PHONE_NBR</tt>.
|
266
|
+
# @raise [TextParseError] if the <tt>PHONE_NBR</tt> is not valid.
|
267
|
+
# @see parse_string
|
268
|
+
def self.parse_phone_number(str, opt={ name: 'PHONE_NBR', length: 12, valid_values: /^(\d{3}-\d{3}-\d{4})?$/ })
|
156
269
|
opt[:name] = "PHONE_NBR" if opt[:name].nil?
|
157
270
|
opt[:length] = 12 if opt[:length].nil?
|
158
271
|
opt[:valid_values] = /^(\d{3}-\d{3}-\d{4})?$/ if opt[:valid_values].nil?
|
159
272
|
return Rsmart::ETL::parse_string str, opt
|
160
273
|
end
|
161
274
|
|
162
|
-
|
275
|
+
# Parse an <tt>EMAIL_TYP_CD</tt> from a String.
|
276
|
+
# @param [String] str the String to be parsed.
|
277
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
278
|
+
# @return [String] the parsed <tt>EMAIL_TYP_CD</tt>.
|
279
|
+
# @raise [TextParseError] if the <tt>EMAIL_TYP_CD</tt> is not valid.
|
280
|
+
# @see parse_string
|
281
|
+
def self.parse_email_type(str, opt={ name: 'EMAIL_TYP_CD', length: 3, valid_values: /^(HM|OTH|WRK)$/i })
|
163
282
|
opt[:name] = "EMAIL_TYP_CD" if opt[:name].nil?
|
164
283
|
opt[:length] = 3 if opt[:length].nil?
|
165
284
|
opt[:valid_values] = /^(HM|OTH|WRK)$/i if opt[:valid_values].nil?
|
166
285
|
return Rsmart::ETL::parse_flag str, opt
|
167
286
|
end
|
168
287
|
|
169
|
-
|
288
|
+
# Parse a <tt>YEAR</tt> from a String.
|
289
|
+
# @param [String] str the String to be parsed.
|
290
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
291
|
+
# @return [String] the parsed <tt>YEAR</tt>.
|
292
|
+
# @raise [TextParseError] if the <tt>YEAR</tt> is not valid.
|
293
|
+
# @see parse_string
|
294
|
+
def self.parse_year(str, opt={ name: 'YEAR', length: 4, valid_values: /^(\d{4})?$/ })
|
170
295
|
opt[:length] = 4 if opt[:length].nil?
|
171
296
|
opt[:valid_values] = /^(\d{4})?$/ if opt[:valid_values].nil?
|
172
297
|
return Rsmart::ETL::parse_string str, opt
|
173
298
|
end
|
174
299
|
|
175
|
-
|
300
|
+
# Parse a <tt>CITIZENSHIP_TYPE_CODE</tt> from a String.
|
301
|
+
# @param [String] str the String to be parsed.
|
302
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
303
|
+
# @return [String] the parsed <tt>CITIZENSHIP_TYPE_CODE</tt>.
|
304
|
+
# @raise [TextParseError] if the <tt>CITIZENSHIP_TYPE_CODE</tt> is not valid.
|
305
|
+
# @see parse_string
|
306
|
+
def self.parse_citizenship_type(str, opt={ name: 'CITIZENSHIP_TYPE_CODE', valid_values: /^([1-4])$/ })
|
176
307
|
opt[:name] = "CITIZENSHIP_TYPE_CODE" if opt[:name].nil?
|
177
308
|
opt[:valid_values] = /^([1-4])$/ if opt[:valid_values].nil?
|
178
309
|
return Rsmart::ETL::parse_flag str, opt
|
179
310
|
end
|
180
311
|
|
181
|
-
|
182
|
-
|
312
|
+
# Parse a <tt>DEGREE</tt> from a String.
|
313
|
+
# @param [String] str the String to be parsed.
|
314
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
315
|
+
# @return [String] the parsed <tt>DEGREE</tt>.
|
316
|
+
# @raise [TextParseError] if the <tt>DEGREE</tt> is not valid.
|
317
|
+
# @see parse_string
|
318
|
+
def self.parse_degree(str, opt={ name: 'DEGREE', length: 5 })
|
183
319
|
opt[:name] = "DEGREE" if opt[:name].nil?
|
184
320
|
opt[:length] = 5 if opt[:length].nil?
|
185
321
|
opt[:valid_values] = /^(AS|BA|BComm|BEd|BS|DA|DC|DD|DDS|DEng|DFA|DH|DHA|DMin|DPA|DSN|DVM|DVS|HS|JD|LLD|LLM|MA|MAEd|MArch|MBA|MD|MDS|MDiv|MEE|MEd|MEng|MFA|MIS|MLS|MPA|MPE|MPH|MPd|MPhil|MS|MSEd|MST|MSW|MTh|PhD|PharD|ScD|ThD|UKNW)?$/ if opt[:valid_values].nil?
|
@@ -187,21 +323,33 @@ module Rsmart::ETL::GRM
|
|
187
323
|
return Rsmart::ETL::parse_flag str, opt
|
188
324
|
end
|
189
325
|
|
190
|
-
#
|
191
|
-
# fields that matches
|
192
|
-
|
326
|
+
# Parse an <tt>ACTV_IND</tt> from a String.
|
327
|
+
# @note Designed specifically for <tt>ACTV_IND</tt>, but could be used on *any* fields that matches <tt>(Y|N)</tt>.
|
328
|
+
# @param [String] str the String to be parsed.
|
329
|
+
# @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}.
|
330
|
+
# @return [String] the parsed <tt>ACTV_IND</tt>.
|
331
|
+
# @raise [TextParseError] if the <tt>ACTV_IND</tt> is not valid.
|
332
|
+
# @see parse_string
|
333
|
+
def self.parse_actv_ind(str, opt={ name: 'ACTV_IND', default: 'Y', valid_values: /^(Y|N)$/i })
|
193
334
|
# `ACTV_IND` varchar(1) COLLATE utf8_bin DEFAULT 'Y',
|
194
|
-
opt[:name] = "
|
335
|
+
opt[:name] = "ACTV_IND" if opt[:name].nil?
|
195
336
|
opt[:default] = "Y" if opt[:default].nil?
|
196
337
|
opt[:valid_values] = /^(Y|N)$/i if opt[:valid_values].nil?
|
197
338
|
return Rsmart::ETL::parse_flag str, opt
|
198
339
|
end
|
199
340
|
|
200
|
-
#
|
201
|
-
# fields that matches
|
202
|
-
|
341
|
+
# Parses the <tt>ACTV_IND</tt> by column :name and mutates the SQL statement accordingly.
|
342
|
+
# @note Designed specifically for <tt>ACTV_IND</tt>, but could be used on *any* fields that matches <tt>(Y|N)</tt>.
|
343
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
344
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
345
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
346
|
+
# @param opt [Hash] options Hash will be passed through to {parse_actv_ind}.
|
347
|
+
# @return [void]
|
348
|
+
# @see parse_actv_ind
|
349
|
+
# @see mutate_sql_stmt!
|
350
|
+
def self.parse_actv_ind!(row, insert_str, values_str, opt={ name: 'ACTV_IND' })
|
203
351
|
# `ACTV_IND` varchar(1) COLLATE utf8_bin DEFAULT 'Y',
|
204
|
-
opt[:name] = "
|
352
|
+
opt[:name] = "ACTV_IND" if opt[:name].nil?
|
205
353
|
actv_ind = parse_actv_ind row[ Rsmart::ETL::to_symbol( opt[:name] ) ]
|
206
354
|
Rsmart::ETL::mutate_sql_stmt! insert_str, opt[:name], values_str, actv_ind
|
207
355
|
end
|
data/lib/rsmart_toolbox/etl.rb
CHANGED
@@ -16,13 +16,17 @@
|
|
16
16
|
|
17
17
|
require "rsmart_toolbox"
|
18
18
|
|
19
|
+
# rSmart extract, transform and load methods.
|
19
20
|
module Rsmart::ETL
|
20
21
|
|
22
|
+
# Any text parsing related errors will use this Exception.
|
21
23
|
class TextParseError < StandardError
|
22
24
|
end
|
23
25
|
|
26
|
+
# Prepares an Exception for consistent error handling.
|
24
27
|
# @param [String, Exception] e the error to handle
|
25
28
|
# @return [Exception] an Exception with a message formatted with $INPUT_LINE_NUMBER.
|
29
|
+
# @raise [ArgumentError] if an invalid argument is passed.
|
26
30
|
def self.error(e)
|
27
31
|
if e.kind_of? String
|
28
32
|
# default to TextParseError
|
@@ -34,8 +38,10 @@ module Rsmart::ETL
|
|
34
38
|
raise ArgumentError, "Unsupported error type: #{e.class}"
|
35
39
|
end
|
36
40
|
|
41
|
+
# Prepares an Exception for consistent warning handling.
|
37
42
|
# @param [String, Exception] e the warning to handle
|
38
43
|
# @return [Exception] an Exception with a message formatted with $INPUT_LINE_NUMBER.
|
44
|
+
# @raise [ArgumentError] if an invalid argument is passed.
|
39
45
|
def self.warning(e)
|
40
46
|
if e.kind_of? String
|
41
47
|
# default to TextParseError
|
@@ -47,6 +53,7 @@ module Rsmart::ETL
|
|
47
53
|
raise ArgumentError, "Unsupported error type: #{e.class}"
|
48
54
|
end
|
49
55
|
|
56
|
+
# Tests whether the subject matches one of the valid values.
|
50
57
|
# @param [String, #match] subject used for validity checking.
|
51
58
|
# @param [Array<Object>, Regexp] valid_values all of the possible valid values.
|
52
59
|
# @option opt [Boolean] :case_sensitive performs case sensitive matching
|
@@ -73,6 +80,7 @@ module Rsmart::ETL
|
|
73
80
|
return false
|
74
81
|
end
|
75
82
|
|
83
|
+
# Matches the input against a set of well known boolean patterns.
|
76
84
|
# @param [String] str String to be matched against well known boolean patterns.
|
77
85
|
# @option opt [Boolean] :default the default return value if str is empty.
|
78
86
|
# @return [Boolean] the result of matching the str input against well known boolean patterns.
|
@@ -92,9 +100,11 @@ module Rsmart::ETL
|
|
92
100
|
raise Rsmart::ETL::error TextParseError.new "invalid value for Boolean: '#{str}'"
|
93
101
|
end
|
94
102
|
|
103
|
+
# Encodes the input String and replaces invalid or undefined characters.
|
95
104
|
# @param [String] str the String to be encoded and invalid characters replaced with valid characters.
|
96
105
|
# @option opt [String] :encoding the character encoding to use.
|
97
106
|
# @return [String] the result of encoding the String and replacing invalid characters with valid characters.
|
107
|
+
# @see String#encode
|
98
108
|
def self.encode(str, opt={ encoding: "UTF-8" } )
|
99
109
|
opt[:encoding] = "UTF-8" if opt[:encoding].nil?
|
100
110
|
str.encode( opt[:encoding], :invalid => :replace,
|
@@ -113,7 +123,7 @@ module Rsmart::ETL
|
|
113
123
|
encode( str.downcase.gsub(/\s+/, "_").gsub(/\W+/, "") ).to_sym
|
114
124
|
end
|
115
125
|
|
116
|
-
# Mutates insert_str and values_str with column_name and value respectively.
|
126
|
+
# Mutates two sides of a SQL insert statement: insert_str and values_str with column_name and value respectively.
|
117
127
|
# Proper SQL value quoting will be performed based on object type.
|
118
128
|
# @param [String] insert_str the left side of the insert statement (i.e. columns)
|
119
129
|
# @param [String] column_name the column name to append to insert_str.
|
@@ -142,6 +152,8 @@ module Rsmart::ETL
|
|
142
152
|
return str.to_s.gsub("'", "\\\\'")
|
143
153
|
end
|
144
154
|
|
155
|
+
# Parses a string using common parsing behavior with options. This method forms the foundation
|
156
|
+
# of all the other parsing methods.
|
145
157
|
# @param [String] str the String to be parsed.
|
146
158
|
# @option opt [String, #to_s] :default the default return value if str is empty. Must respond to #to_s
|
147
159
|
# @option opt [Boolean] :escape_single_quotes escape single quote characters.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsmart_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lance Speelmon
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
sKRWzEtHFamxQaIspOja5O4oQKiCbWa90fEuIoCtwyy1rQtL9VKoDTs4vZASXNuc
|
31
31
|
F/lEyekXSjN36uTtlt4LkKLn/k7k5gRbt4+C9Q==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2014-08-
|
33
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: builder
|
metadata.gz.sig
CHANGED