module Rsmart::ETL::GRM
rSmart Grant and Research Management methods.
Public Class Methods
Parse an ACTV_IND
from a String. @note Designed specifically for ACTV_IND
, but could be used on any fields that matches (Y|N)
. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed ACTV_IND
. @raise [TextParseError] if the ACTV_IND
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 336 def self.parse_actv_ind(str, opt={ name: 'ACTV_IND', default: 'Y', valid_values: /^(Y|N)$/i }) # `ACTV_IND` varchar(1) COLLATE utf8_bin DEFAULT 'Y', opt[:name] = "ACTV_IND" if opt[:name].nil? opt[:default] = "Y" if opt[:default].nil? opt[:valid_values] = /^(Y|N)$/i if opt[:valid_values].nil? return Rsmart::ETL::parse_flag str, opt end
Parses the ACTV_IND
by column :name and mutates the SQL statement accordingly. @note Designed specifically for ACTV_IND
, but could be used on any fields that matches (Y|N)
. @param row [CSV::Row] the CSV Row being parsed @param insert_str [String] the left side of the insert statement (i.e. columns) @param values_str [String] the right side of the insert statement (i.e. values) @param opt [Hash] options Hash will be passed through to {parse_actv_ind}. @return [void] @see parse_actv_ind
@see mutate_sql_stmt!
# File lib/rsmart_toolbox/etl/grm.rb, line 353 def self.parse_actv_ind!(row, insert_str, values_str, opt={ name: 'ACTV_IND' }) # `ACTV_IND` varchar(1) COLLATE utf8_bin DEFAULT 'Y', opt[:name] = "ACTV_IND" if opt[:name].nil? actv_ind = parse_actv_ind row[ Rsmart::ETL::to_symbol( opt[:name] ) ] Rsmart::ETL::mutate_sql_stmt! insert_str, opt[:name], values_str, actv_ind end
Parse an ADDR_TYP_CD
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed ADDR_TYP_CD
. @raise [TextParseError] if the ADDR_TYP_CD
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 204 def self.parse_address_type_code(str, opt={ name: 'ADDR_TYP_CD', length: 3, valid_values: /^(HM|OTH|WRK)$/i }) opt[:name] = "ADDR_TYP_CD" if opt[:name].nil? opt[:length] = 3 if opt[:length].nil? opt[:valid_values] = /^(HM|OTH|WRK)$/i if opt[:valid_values].nil? return Rsmart::ETL::parse_flag str, opt end
Parse a CITIZENSHIP_TYPE_CODE
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed CITIZENSHIP_TYPE_CODE
. @raise [TextParseError] if the CITIZENSHIP_TYPE_CODE
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 309 def self.parse_citizenship_type(str, opt={ name: 'CITIZENSHIP_TYPE_CODE', valid_values: /^([1-5])$/ }) opt[:name] = "CITIZENSHIP_TYPE_CODE" if opt[:name].nil? opt[:valid_values] = /^([1-5])$/ if opt[:valid_values].nil? return Rsmart::ETL::parse_flag str, opt end
Parses the COUNTRY_CODE
by column :name and mutates the SQL statement accordingly. @param row [CSV::Row] the CSV Row being parsed @param insert_str [String] the left side of the insert statement (i.e. columns) @param values_str [String] the right side of the insert statement (i.e. values) @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}. @return [void] @see parse_string!
# File lib/rsmart_toolbox/etl/grm.rb, line 47 def self.parse_country_code!(row, insert_str, values_str, opt={ name: 'COUNTRY_CODE', length: 3 }) # `COUNTRY_CODE` char(3) COLLATE utf8_bin DEFAULT NULL, opt[:name] = "COUNTRY_CODE" if opt[:name].nil? opt[:length] = 3 if opt[:length].nil? Rsmart::ETL::parse_string! row, insert_str, values_str, opt end
Parse a DEGREE
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed DEGREE
. @raise [TextParseError] if the DEGREE
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 321 def self.parse_degree(str, opt={ name: 'DEGREE', length: 5 }) opt[:name] = "DEGREE" if opt[:name].nil? opt[:length] = 5 if opt[:length].nil? 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? opt[:upcase] = false if opt[:upcase].nil? return Rsmart::ETL::parse_flag str, opt end
Parse an EMAIL_ADDRESS
from a String. @note The result is validated against a email address RegExp. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed EMAIL_ADDRESS
. @raise [TextParseError] if the email address is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 119 def self.parse_email_address(str, opt={ name: 'EMAIL_ADDRESS', length: 60 }) # `EMAIL_ADDRESS` varchar(60) COLLATE utf8_bin DEFAULT NULL, opt[:name] = "EMAIL_ADDRESS" if opt[:name].nil? opt[:length] = 60 if opt[:length].nil? opt[:valid_values] = /^(([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))?$/ if opt[:valid_values].nil? return Rsmart::ETL::parse_string str, opt end
Parses the EMAIL_ADDRESS
by column :name and mutates the SQL statement accordingly. @param row [CSV::Row] the CSV Row being parsed @param insert_str [String] the left side of the insert statement (i.e. columns) @param values_str [String] the right side of the insert statement (i.e. values) @param opt [Hash] options Hash will be passed through to {parse_email_address}. @return [void] @see parse_email_address
@see mutate_sql_stmt!
# File lib/rsmart_toolbox/etl/grm.rb, line 135 def self.parse_email_address!(row, insert_str, values_str, opt={ name: 'EMAIL_ADDRESS' }) # `EMAIL_ADDRESS` varchar(60) COLLATE utf8_bin DEFAULT NULL, opt[:name] = "EMAIL_ADDRESS" if opt[:name].nil? email_address = parse_email_address row[ Rsmart::ETL::to_symbol( opt[:name] ) ] Rsmart::ETL::mutate_sql_stmt! insert_str, opt[:name], values_str, email_address end
Parse an EMAIL_TYP_CD
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed EMAIL_TYP_CD
. @raise [TextParseError] if the EMAIL_TYP_CD
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 284 def self.parse_email_type(str, opt={ name: 'EMAIL_TYP_CD', length: 3, valid_values: /^(HM|OTH|WRK)$/i }) opt[:name] = "EMAIL_TYP_CD" if opt[:name].nil? opt[:length] = 3 if opt[:length].nil? opt[:valid_values] = /^(HM|OTH|WRK)$/i if opt[:valid_values].nil? return Rsmart::ETL::parse_flag str, opt end
Parse an EMP_STAT_CD
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed EMP_STAT_CD
. @raise [TextParseError] if the EMP_STAT_CD
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 178 def self.parse_emp_stat_cd(str, opt={ name: 'EMP_STAT_CD', valid_values: /^(A|D|L|N|P|R|S|T)$/i }) # `EMP_STAT_CD` varchar(40) COLLATE utf8_bin DEFAULT NULL, opt[:name] = "EMP_STAT_CD" if opt[:name].nil? opt[:valid_values] = /^(A|D|L|N|P|R|S|T)$/i if opt[:valid_values].nil? return Rsmart::ETL::parse_flag str, opt end
Parse an EMP_TYP_CD
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed EMP_TYP_CD
. @raise [TextParseError] if the EMP_TYP_CD
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 191 def self.parse_emp_typ_cd(str, opt={ name: 'EMP_TYP_CD', valid_values: /^(N|O|P)$/i }) # `EMP_TYP_CD` varchar(40) COLLATE utf8_bin DEFAULT NULL, opt[:name] = "EMP_TYP_CD" if opt[:name].nil? opt[:valid_values] = /^(N|O|P)$/i if opt[:valid_values].nil? return Rsmart::ETL::parse_flag str, opt end
Parse a NM_TYP_CD
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed NM_TYP_CD
. @raise [TextParseError] if the NM_TYP_CD
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 217 def self.parse_name_code(str, opt={ name: 'NM_TYP_CD', length: 4, valid_values: /^(OTH|PRFR|PRM)$/i }) opt[:name] = "NM_TYP_CD" if opt[:name].nil? opt[:length] = 4 if opt[:length].nil? opt[:valid_values] = /^(OTH|PRFR|PRM)$/i if opt[:valid_values].nil? return Rsmart::ETL::parse_flag str, opt end
Parses the OWNED_BY_UNIT
by column :name and mutates the SQL statement accordingly. @param row [CSV::Row] the CSV Row being parsed @param insert_str [String] the left side of the insert statement (i.e. columns) @param values_str [String] the right side of the insert statement (i.e. values) @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}. @return [void] @see parse_string!
# File lib/rsmart_toolbox/etl/grm.rb, line 104 def self.parse_owned_by_unit!(row, insert_str, values_str, opt={ name: 'OWNED_BY_UNIT', required: true, length: 8 }) # `OWNED_BY_UNIT` varchar(8) COLLATE utf8_bin NOT NULL, opt[:name] = "OWNED_BY_UNIT" if opt[:name].nil? opt[:required] = true if opt[:required].nil? opt[:length] = 8 if opt[:length].nil? Rsmart::ETL::parse_string! row, insert_str, values_str, opt end
Parse a PHONE_NBR
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed PHONE_NBR
. @raise [TextParseError] if the PHONE_NBR
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 271 def self.parse_phone_number(str, opt={ name: 'PHONE_NBR', length: 12, valid_values: /^(\d{3}-\d{3}-\d{4})?$/ }) opt[:name] = "PHONE_NBR" if opt[:name].nil? opt[:length] = 12 if opt[:length].nil? opt[:valid_values] = /^(\d{3}-\d{3}-\d{4})?$/ if opt[:valid_values].nil? return Rsmart::ETL::parse_string str, opt end
Parse a PHONE_TYP_CD
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed PHONE_TYP_CD
. @raise [TextParseError] if the PHONE_TYP_CD
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 258 def self.parse_phone_type(str, opt={ name: 'PHONE_TYP_CD', length: 3, valid_values: /^(FAX|HM|MBL|OTH|WRK)$/i }) opt[:name] = "PHONE_TYP_CD" if opt[:name].nil? opt[:length] = 3 if opt[:length].nil? opt[:valid_values] = /^(FAX|HM|MBL|OTH|WRK)$/i if opt[:valid_values].nil? return Rsmart::ETL::parse_flag str, opt end
Parses the POSTAL_CODE
by column :name and mutates the SQL statement accordingly. @param row [CSV::Row] the CSV Row being parsed @param insert_str [String] the left side of the insert statement (i.e. columns) @param values_str [String] the right side of the insert statement (i.e. values) @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}. @return [void] @see parse_string!
# File lib/rsmart_toolbox/etl/grm.rb, line 90 def self.parse_postal_code!(row, insert_str, values_str, opt={ name: 'POSTAL_CODE', length: 15 }) # `POSTAL_CODE` varchar(15) COLLATE utf8_bin DEFAULT NULL, opt[:name] = "POSTAL_CODE" if opt[:name].nil? opt[:length] = 15 if opt[:length].nil? Rsmart::ETL::parse_string! row, insert_str, values_str, opt end
Parse a PREFIX_NM
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed PREFIX_NM
. @raise [TextParseError] if the PREFIX_NM
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 230 def self.parse_prefix(str, opt={ name: 'PREFIX_NM', length: 3, valid_values: /^(Ms|Mrs|Mr|Dr)?$/ }) opt[:name] = "PREFIX_NM" if opt[:name].nil? opt[:length] = 3 if opt[:length].nil? opt[:valid_values] = /^(Ms|Mrs|Mr|Dr)?$/ if opt[:valid_values].nil? opt[:upcase] = false if opt[:upcase].nil? return Rsmart::ETL::parse_flag str, opt end
Parse a PRNCPL_ID
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed PRNCPL_ID
. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 147 def self.parse_principal_id(str, opt={ name: 'PRNCPL_ID', required: true, length: 40 }) # `PRNCPL_ID` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '', opt[:name] = "PRNCPL_ID" if opt[:name].nil? opt[:required] = true if opt[:required].nil? opt[:length] = 40 if opt[:length].nil? Rsmart::ETL::parse_string str, opt end
Parse a PRNCPL_NM
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed PRNCPL_NM
. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 160 def self.parse_principal_name(str, opt={ name: 'PRNCPL_NM', required: true, length: 100 }) # `PRNCPL_NM` varchar(100) COLLATE utf8_bin NOT NULL, opt[:name] = "PRNCPL_NM" if opt[:name].nil? opt[:length] = 100 if opt[:length].nil? opt[:required] = true if opt[:required].nil? prncpl_nm = Rsmart::ETL::parse_string str, opt unless prncpl_nm =~ /^([a-z0-9\@\.\_\-]+)$/ raise Rsmart::ETL::error TextParseError.new "Illegal prncpl_nm found: '#{prncpl_nm}'" end return prncpl_nm end
Parses the ROLODEX_ID
by column :name and mutates the SQL statement accordingly. @param row [CSV::Row] the CSV Row being parsed @param insert_str [String] the left side of the insert statement (i.e. columns) @param values_str [String] the right side of the insert statement (i.e. values) @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_integer!}. @return [void] @see parse_integer!
# File lib/rsmart_toolbox/etl/grm.rb, line 32 def self.parse_rolodex_id!(row, insert_str, values_str, opt={ name: 'ROLODEX_ID', required: true, length: 6 }) # `ROLODEX_ID` decimal(6,0) NOT NULL DEFAULT '0', opt[:name] = "ROLODEX_ID" if opt[:name].nil? opt[:required] = true if opt[:required].nil? opt[:length] = 6 if opt[:length].nil? Rsmart::ETL::parse_integer! row, insert_str, values_str, opt end
Parses the SPONSOR_CODE
by column :name and mutates the SQL statement accordingly. @param row [CSV::Row] the CSV Row being parsed @param insert_str [String] the left side of the insert statement (i.e. columns) @param values_str [String] the right side of the insert statement (i.e. values) @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}. @return [void] @see parse_string!
# File lib/rsmart_toolbox/etl/grm.rb, line 75 def self.parse_sponsor_code!(row, insert_str, values_str, opt={ name: 'SPONSOR_CODE', required: false, length: 6 }) # `SPONSOR_CODE` char(6) COLLATE utf8_bin NOT NULL DEFAULT '', opt[:name] = "SPONSOR_CODE" if opt[:name].nil? opt[:required] = false if opt[:required].nil? opt[:length] = 6 if opt[:length].nil? Rsmart::ETL::parse_string! row, insert_str, values_str, opt end
Parses the STATE
by column :name and mutates the SQL statement accordingly. @param row [CSV::Row] the CSV Row being parsed @param insert_str [String] the left side of the insert statement (i.e. columns) @param values_str [String] the right side of the insert statement (i.e. values) @param opt [Hash] options Hash will be passed through to {Rsmart::ETL.parse_string!}. @return [void] @see parse_string!
# File lib/rsmart_toolbox/etl/grm.rb, line 61 def self.parse_state!(row, insert_str, values_str, opt={ name: 'STATE', length: 30 }) # `STATE` varchar(30) COLLATE utf8_bin DEFAULT NULL, opt[:name] = "STATE" if opt[:name].nil? opt[:length] = 30 if opt[:length].nil? Rsmart::ETL::parse_string! row, insert_str, values_str, opt end
Parse a SUFFIX_NM
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed SUFFIX_NM
. @raise [TextParseError] if the SUFFIX_NM
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 244 def self.parse_suffix(str, opt={ name: 'SUFFIX_NM', length: 3, valid_values: /^(Jr|Sr|Mr|Md)?$/ }) opt[:name] = "SUFFIX_NM" if opt[:name].nil? opt[:length] = 3 if opt[:length].nil? opt[:valid_values] = /^(Jr|Sr|Mr|Md)?$/ if opt[:valid_values].nil? opt[:upcase] = false if opt[:upcase].nil? return Rsmart::ETL::parse_flag str, opt end
Parse a YEAR
from a String. @param [String] str the String to be parsed. @param [Hash] opt options Hash will be passed through to {Rsmart::ETL.parse_string}. @return [String] the parsed YEAR
. @raise [TextParseError] if the YEAR
is not valid. @see parse_string
# File lib/rsmart_toolbox/etl/grm.rb, line 297 def self.parse_year(str, opt={ name: 'YEAR', length: 4, valid_values: /^(\d{4})?$/ }) opt[:length] = 4 if opt[:length].nil? opt[:valid_values] = /^(\d{4})?$/ if opt[:valid_values].nil? return Rsmart::ETL::parse_string str, opt end
Performs an XML XSD schema validation using the published schema. @note Any schema validation errors are output to STDOUT via puts. @param xml_filename [String] A path to the XML file to be validated. @return [Boolean] true if no validation errors are found; otherwise false.
# File lib/rsmart_toolbox/etl/grm.rb, line 364 def self.validate_hr_xml(xml_filename) ret_val = false # validate the resulting XML file against the official XSD schema uri = URI 'https://raw.githubusercontent.com/KualiCo/ce-tech-docs/master/hrmanifest.xsd' Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| Tempfile.open "hrmanifest.xsd" do |schema| request = Net::HTTP::Get.new uri.request_uri http.request request do |response| response.read_body do |segment| schema.write(segment) end end schema.rewind xsd = Nokogiri::XML::Schema schema doc = Nokogiri::XML File.read xml_filename xml_errors = xsd.validate doc if xml_errors.empty? puts "Congratulations! The XML file passes XSD schema validation! w00t!\n\n" ret_val = true else puts "Sorry, the XML file does NOT pass XSD schema validation!:" xml_errors.each do |error| puts error.message end end end # schema end return ret_val end