Created
September 10, 2009 21:30
-
-
Save eric1234/184842 to your computer and use it in GitHub Desktop.
Simple method to help import a data while normalizing at the same time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Most simply just returns the data. But can allow for adjusting of the | |
# data a bit more to ensure more normalized data or format conversions. | |
# | |
# * If data is blank? (as defined by ActiveSupport) then nil is | |
# returned. | |
# * If the block is given then that will be called and the return | |
# value will be passed back. If the value is blank? then the block | |
# will not be called and nil will be returned (to avoid checks | |
# in the blocks) | |
# | |
# Example: | |
# | |
# user = User.new \ | |
# :last_name => import(row['INDIVIDUAL_last_name']), | |
# :first_name => import(row['INDIVIDUAL_first_name']), | |
# :date_of_birth => import(row['INDIVIDUAL_date_of_birth']) {|d| Date.parse(d)}, | |
def import(data, &blk) | |
return nil if data.blank? | |
blk = proc {|x| x} unless block_given? | |
blk[data] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment