class Migration
Public Instance Methods
transform_file(old_fname)
click to toggle source
# File lib/migration/migrate_old_entries.rb, line 10 def transform_file(old_fname) config = WorkLoggerConfiguration.load old_file_match = old_fname.match(/(?<year>\d\d\d\d)-(?<month>\d\d)-(?<day>\d\d).txt/) unless old_file_match.nil? year = old_file_match[:year] month = old_file_match[:month] day = old_file_match[:day] new_fname = get_filename(config, year, month, day) old_file = File.open(old_fname, 'r') new_file = File.open(new_fname, 'w') old_file.each_line do |line| match = line.match(/(\d\d?:\d\d).+/)&.captures new_file.write("#{match[0]}\n") unless match.nil? || match.empty? end old_file.close new_file.close end end