Module: Unidom::Common::DataHelper
- Defined in:
- lib/unidom/common/data_helper.rb
Instance Method Summary collapse
Instance Method Details
#each_csv_row(file_name, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/unidom/common/data_helper.rb', line 8 def each_csv_row(file_name, &block) started_at = Time.now puts "Importing from CSV file: #{file_name}." if file_name.blank? puts "#{file_name} doesn't exist." abort 1 end CSV.foreach file_name, { encoding: 'UTF-8', headers: :first_row }, &block puts "#{Time.now-started_at} seconds was spent to handle the given CSV." end |
#parse_time(date_text, default = Time.now) ⇒ Object
24 25 26 27 28 |
# File 'lib/unidom/common/data_helper.rb', line 24 def parse_time(date_text, default = Time.now) return default if date_text.blank? date = Date.parse date_text Time.utc date.year, date.month, date.day end |