CSC/ECE 517 Fall 2019 - E1938. OSS project Duke Blue: Fix import glitches

From Expertiza_Wiki
Revision as of 19:44, 28 October 2019 by Psdravid (talk | contribs)
Jump to navigation Jump to search

Issue #918
New code introduced is as follows.
File:app/helpers/import_topics_helper.rb
Code: def self.define_attributes(row_hash)

   attributes = {}
   if !row_hash[:description].nil? and !row_hash[:description].ascii_only?
     row_hash[:description] = self.trim_non_ascii(row_hash[:description])
     puts row_hash[:description]
   end
   attributes["topic_identifier"] = row_hash[:topic_identifier].strip
   attributes["topic_name"] = row_hash[:topic_name].strip
   attributes["max_choosers"] = row_hash[:max_choosers].strip
   attributes
 end
 def self.trim_non_ascii(string)
   string.split().each do |char|
     !char.ascii_only? ? string.tr!(char, ' ') : nil
   end
   string.gsub!(/\s+/, ' ')
 end