lib/echi-converter.rb in echi-converter-0.1.0 vs lib/echi-converter.rb in echi-converter-0.1.1

- old
+ new

@@ -81,11 +81,11 @@ value = @binary_file.read(length).unpack("M").first.to_s.rstrip #Process individual bits that are booleans when 'bool' value = @binary_file.read(length).unpack("b8").last.to_s #Process that one wierd boolean that is actually an int, instead of a bit - when 'bool_int' + when 'boolint' value = @binary_file.read(length).unpack("U").first.to_i #Change the values of the field to Y/N for the varchar(1) representation of BOOLEAN if value == 1 value = 'Y' else @@ -117,25 +117,30 @@ end bool_cnt = 0 record_cnt = 0 while @binary_file.eof == FALSE do - @log.debug '<====================START RECORD====================>' + @log.debug '<====================START RECORD ' + record_cnt.to_s + ' ====================>' echi_record = EchiRecord.new @echi_schema["fields"].each do | field | #We handle the 'boolean' fields differently, as they are all encoded as bits in a single 8-bit byte if field["type"] == 'bool' if bool_cnt == 0 bytearray = dump_binary field["type"], field["length"] end #Ensure we parse the bytearray and set the appropriate flags + #We need to make sure the entire array is not nil, in order to do Y/N + #if Nil we then set all no if bytearray != nil - value = bytearray.slice(bool_cnt,1) + if bytearray.slice(bool_cnt,1) == 1 + value = 'Y' + else + value = 'N' + end else value = 'N' end - @log.debug "Boolie: " + bool_cnt.to_s bool_cnt += 1 if bool_cnt == 8 bool_cnt = 0 end else @@ -147,13 +152,13 @@ end echi_record.save #Scan past the end of line record @binary_file.read(1) + @log.debug '<====================STOP RECORD ' + record_cnt.to_s + ' ====================>' record_cnt += 1 end - @log.debug '<====================STOP RECORD====================>' @binary_file.close #Move the file to the processed directory destination_directory = @workingdirectory + '/../files/processed/' FileUtils.mv(echi_file, destination_directory) @@ -245,11 +250,11 @@ end record_cnt = 0 FasterCSV.foreach(echi_file) do |row| if row != nil - @log.debug '<====================START RECORD====================>' + @log.debug '<====================START RECORD ' + record_cnt.to_s + ' ====================>' echi_record = EchiRecord.new cnt = 0 @echi_schema["fields"].each do | field | if field["type"] == "bool" || field["type"] == "bool_int" case row[cnt] @@ -266,10 +271,10 @@ end end cnt += 1 end echi_record.save - @log.debug '<====================STOP RECORD====================>' + @log.debug '<====================STOP RECORD ' + record_cnt.to_s + ' ====================>' record_cnt += 1 end end #Move the file to the processed directory